• samuel singh 1
  • NEWBIE
  • 0 Points
  • Member since 2021

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 1
    Replies

I need a way to apply lead assignment rules whenever the lead score goes above 99 and the lead review status is complete.

 

Here is my trigger code:

 

 

trigger ApplyLeadAssignmentRules on Lead (before update, before insert) {


    for (Lead l:trigger.new) {


        Decimal score =   l.Score__c;
        String review_status =  l.Review_Status__c;

        if(score == null) score = 0.0;
        if(review_status == null) review_status = '';
            
        if( (score >= 100) && (review_status.equalsIgnoreCase('Complete'))  ){
            Database.DMLOptions dmo = new Database.DMLOptions();
            dmo.assignmentRuleHeader.useDefaultRule = true;
            l.setOptions(dmo);
            Database.update(l);   
        }     

    }


}

 

 

This throws the following exception:

 

Apex script unhandled trigger exception by user/organization:

Source organization:

ApplyLeadAssignmentRules: execution of BeforeUpdate

caused by: System.DmlException: Update failed. First exception on row 0 with id ; first error: SELF_REFERENCE_FROM_TRIGGER, Object (id = 00QQ0000001Q2av) is currently in trigger ApplyLeadAssignmentRules, therefore it cannot recursively update itself: []

 

 

How do I fix this? Any solution?