I have a list of cases to be created / updated. There is a Case assignment rule in my org which assigns new cases to a specified user. Now I want to get these cases assigned to the user specified in the user only based on a flag check and otherwise assign to default owners.
I tried the following piece of code but unable to suppress the assignment rule from executing. Any help on this would be appreciated.
List<Case> cases; // Contains new and existing cases
//This will be set from the UI based on whether the auto assignment of case should happen or not
Boolean useDefaultRule;
Database.DMLOptions options = new Database.DMLOptions();
options.assignmentRuleHeader.useDefaultRule = useDefaultRule;
List<Case> caseList = new List<Case>();
for(Case case : cases){
case.setOptions(options);
caseList.add(case);
}
upsert caseList;
This still triggers auto assignment of rules even if the useDefault flag is set to false. Is there NO way that I can suppress this?