Skip to content

Instantly share code, notes, and snippets.

@jhersh
Created July 27, 2011 20:43
Show Gist options
  • Select an option

  • Save jhersh/1110328 to your computer and use it in GitHub Desktop.

Select an option

Save jhersh/1110328 to your computer and use it in GitHub Desktop.

Revisions

  1. jhersh revised this gist Jul 27, 2011. 1 changed file with 4 additions and 1 deletion.
    5 changes: 4 additions & 1 deletion gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,6 @@
    trigger ApplyAssignmentRules on Lead (after insert) {

    List<User> owner = [Select u.Id From User u where Name = 'User Portal'];
    List<User> owner = [Select u.Id From User u where Name = 'User Portal' limit 1];

    if( owner.isEmpty() )
    return;
    @@ -11,6 +11,9 @@ trigger ApplyAssignmentRules on Lead (after insert) {
    if (l.OwnerId == owner.get(0).Id)
    LeadsToUpdate.add(l);

    if( LeadsToUpdate.isEmpty() )
    return;

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

  2. jhersh created this gist Jul 27, 2011.
    21 changes: 21 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,21 @@
    trigger ApplyAssignmentRules on Lead (after insert) {

    List<User> owner = [Select u.Id From User u where Name = 'User Portal'];

    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);

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

    For (Lead u:LeadsToUpdate)
    u.setOptions( dmo );

    update LeadsToUpdate;
    }