150k views
0 votes
How to force lead assignment rule via Apex while updating or adding the Lead?

User Bbien
by
8.0k points

1 Answer

2 votes

Final answer:

To force lead assignment rule via Apex while updating or adding the lead, you can use the 'Database.DMLOptions' class and the 'AssignmentRuleHeader' object.

Step-by-step explanation:

To force a lead assignment rule via Apex while updating or adding a lead, you can use the 'Database.DMLOptions' class and the 'AssignmentRuleHeader' object. First, create an instance of the 'Database.DMLOptions' class and set the 'AssignmentRuleHeader' object with the value 'true'. Then, assign this instance to the 'DMLOptions' property of the lead record. Finally, perform the DML operation to update or insert the lead record.

Here's an example:

Lead myLead = new Lead();
myLead.FirstName = 'John';
myLead.LastName = 'Doe';

Database.DMLOptions dmlOptions = new Database.DMLOptions();
dmlOptions.assignmentRuleHeader.useDefaultRule = true;

myLead.setOptions(dmlOptions);

insert myLead;.
User Yalei Du
by
8.3k points

No related questions found