Sure, you can run the Lead or Case assignment rules by creating a case or lead from within Salesforce. This is done by either having the rules run automatically on insert or maybe you choose to run them manually at a later time.
But wait! What if you need to run the rules after a lead or case has been created within the context of a trigger. Maybe because it has been created through the Salesforce API or you would like to have some custom logic as to when the rules will be run or even what rules to run (Ex. When the object is created with a particular field value or a particular field value has changed).
Salesforce makes this possible through the DML Options Class. The one caveat is this will need to be executed in an after trigger context.
The code snippet below shows how you can run the default assignment rules in an after insert trigger on the Lead object, the same can be done to run the default assignment rules on the Case object.
If you would like to run a specific assignment rule instead of the default, you can assign the assignmentRuleHeader to the Salesforce Id of the rule (Ex. dmo.assignmentRuleHeader = ‘xxxxxxxxxxxxxxx’).
For more information on this and other DML Options see the Salesforce DML Options Cass.