If you want to create a new Lead via Visualforce or web form with Apex it’s very possible you could overlook the Assignment Rules. As you might know, it’s not even always obvious on the native Lead creation layout. Notice the lower left corner checkbox in the screenshot below.
To enforce Assignment Rules in Apex you’ll need to instantiate the Database.DMLOptions class, set the useDefaultRule property of assignmentRuleHeader to True, and finally call a native method on your Lead called setOptions, with the Database.DMLOptions instance as the argument.
The code below demonstrates:
Database.DMLOptions dmo = new Database.DMLOptions();
dmo.assignmentRuleHeader.useDefaultRule = true;
theLead.setOptions(dmo);
That’s it. Hope it helps.
Happy clouding ~~~











Posted by Tom Burre on November 19, 2009 at 8:35 pm
