function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
saurabhgptsaurabhgpt 

Trigger on Opportunity-Quote sync : System.DmlException: Upsert failed

Hi

 

I have written two triggers on QuoteLineItem and OpportunityLineItem named update_term and  UpdateOppTerms respectively.

I have to establish a synch functionality between  QuoteLineItem and OpportunityLineItem for a custom field of Picklist type called Term__C.

The trigger works fine for Before insert but gives exception on Before update event

Actually when i update a QuoteLineItem then trigger on QuoteLineItem for before update fires which updates the OpportunityLineItem

Since there is a similar trigger on OpportunityLineItem for before update which has to update QuoteLineItem

therefore an exception for recursive update occurs :?

 

Apex trigger UpdateOppTerms caused an unexpected exception, contact your administrator: UpdateOppTerms: execution of AfterUpdate caused by: System.DmlException: Upsert failed. First exception on row 0 with id 0QLR00000008PQEOA2; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, update_term: execution of BeforeUpdate caused by: System.DmlException: Upsert failed. First exception on row 0 with id 00kR0000004UBovIAG; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, UpdateOppTerms: execution of AfterUpdate caused by: System.DmlException: Upsert failed. First exception on row 0 with id 0QLR00000008PQEOA2; first error: SELF_REFERENCE_FROM_TRIGGER, Object (id = 0QLR00000008PQE) is currently in trigger update_term, therefore it cannot recursively update itself: [] Trigger.UpdateOppTerms: line 52, column 4: [] Trigger.update_term: line 55, column 5: []: Trigger.UpdateOppTerms: line 52, column 4  

 

How can i resolve this issue for recursive update ? can anyone help?

 

marioluisscmarioluissc

Please, show your apex code.

 

so I realized, you try to update the same object the trigger, then cause the error
try calling the same record with SOQL, and then update this record called by SOQL.

ex: Object xxxx = [select id from Object where id= Trigger.new[0].id];
update xxxx;

 

I hope i helped you.