Notifications
Clear all
Oct 06, 2021 5:47 pm
Trigger recursion error - I am getting the following error:
- QuoteTrigger: execution of BeforeUpdate caused by: System.DmlException: Update failed. First exception on row 0 with id 0Q05D0000007jC3SAI; first error: SELF_REFERENCE_FROM_TRIGGER, Object (id = 0Q05D0000007jC3) is currently in trigger QuoteTrigger, therefore it cannot recursively update itself: [] Trigger.QuoteTrigger: line 35, column 1
Trigger code is:
// Uncheck all latest quotes except for the one manually made latest if(Trigger.isUpdate && Trigger.isBefore){ if(Trigger.new[0].Latest_quote__c == true) { // proceed only if latest quote is checked List<Quote> qtList = [SELECT Id, opportunityId, Latest_quote__c FROM quote WHERE opportunityId IN :oppIds ORDER BY LastModifiedDate DESC]; if (qtList.size() > 1) { for(Integer i = 0; i < qtList.size(); i++){ // uncheck all from being latest qtList[i].Latest_quote__c = false; } } qtList[0].Latest_quote__c = true; // mark only the manually marked as checked update qtList; } }
1 Reply
Oct 08, 2021 5:15 am
The best solution to this recursion error / infinite loop error / maximum trigger depth exceeded error on update trigger, is to use a flow instead: https://youtu.be/RZOClRIpZeg