Tag Archives: Assignment Rules

Run Case or Lead Assignment Rule From Apex

Run Lead Assignment From Apex Sample Code:

//Get your Lead records
List<Lead> leadList = [SELECT Id From Lead LIMIT 10];

if(!leadList.isEmpty()) {
    //Run Lead assignment rule from apex
    Database.DMLOptions dmlOption = new Database.DMLOptions();
    dmlOption.assignmentRuleHeader.useDefaultRule = true;
    Database.update(leadList, dmlOption);
}

Run Case Assignment From Apex Sample Code:

//Get your Case records
List<Case> caseList = [SELECT Id From Case LIMIT 10];

if(!caseList.isEmpty()) {
    //Run Case assignment rule from apex
    Database.DMLOptions dmlOption = new Database.DMLOptions();
    dmlOption.assignmentRuleHeader.useDefaultRule = true;
    Database.update(caseList, dmlOption);
}