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 ~~~
Related posts:
- How to avoid governor limits with sendEmail in Apex You can send emails programmatically in Apex, but if you’re...
- The User, Visualforce and Apex — about a drop down menu Let’s say you coded a custom view or report using...
Related posts brought to you by Yet Another Related Posts Plugin.












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