Skip to content

Instantly share code, notes, and snippets.

@jhersh
Created July 27, 2011 20:43
Show Gist options
  • Save jhersh/1110328 to your computer and use it in GitHub Desktop.
Save jhersh/1110328 to your computer and use it in GitHub Desktop.
trigger ApplyAssignmentRules on Lead (after insert) {
List<User> owner = [Select u.Id From User u where Name = 'User Portal' limit 1];
if( owner.isEmpty() )
return;
List<Lead> LeadsToUpdate = new List<Lead>();
For (Lead l:trigger.new)
if (l.OwnerId == owner.get(0).Id)
LeadsToUpdate.add(l);
if( LeadsToUpdate.isEmpty() )
return;
Database.DMLOptions dmo = new Database.DMLOptions();
dmo.assignmentRuleHeader.useDefaultRule= true;
For (Lead u:LeadsToUpdate)
u.setOptions( dmo );
update LeadsToUpdate;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment