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
SaaniaSaania 

Two triggers in deadlock

Hi,

I have a trigger in Opportunity object (UpdateOpportunityAmount) that updates the Amount field based on stage. This trigger calls the Opportunity Line Item object to update the unit price accordingly.

In Opportunity Line Item we have a trigger (UpdateOpportunityProduct) that sets certain fields in opportunity object, based on selected Product. The error I am getting is.
Code:
UpdateOpportunityAmount: execution of BeforeUpdate

caused by: System.DmlException: Update failed. First exception on row 0 with id 00k60000005cTOLAA2; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, UpdateOpportunityProduct: execution of BeforeUpdate

caused by: System.DmlException: Update failed. First exception on row 0 with id 0066000000APwGhAAL; first error: UNKNOWN_EXCEPTION, Object (id = 0066000000APwGh) is currently being updated in trigger UpdateOpportunityAmount: [Id]

Trigger.UpdateOpportunityProduct: line 45, column 17

Trigger.UpdateOpportunityAmount: line 27, column 17

I know the reason, I just cant think of a solution or a workaround. because of the before update/ after update issue with triggers, i cant perform the Opportunity Line Item operation within the Opportunity Trigger.Any help would be highly appreciated.

Thanks,

 

MikeGoelzerMikeGoelzer
Instead of having a trigger to update the Opportunity.Amount, could you use a roll-up formula field to sums up all the child product amounts?  I think you want to break the cyclic dependency between the parent and children objects somehow.

There are some generic ways to force Apex code to run on another thread (e.g., google for "apex cron jobs" or just add a manual Update button on the page layout), which lets you get back in after the lock has been released, but that's not really the problem, right?


Message Edited by MikeGoelzer on 09-15-2008 04:39 PM