1

I have triggers on both, Opportunity and OpportunityLineItem (OLI). On a specific update to an Opportunity, there's a big process started at the end of which I need to update all OLIs related to the Opportunities processed.

I do not know when or why exactly the parent Opportunities are updated through an OLI update, but in this case they are and throw an error (SELF_REFERENCE_FROM_TRIGGER). I do know in general on how to prevent recursive calls, but in this problem I can not even check for recursiveness before the error is thrown. I also do have roll-up summary fields on Opportunity.

try
{
    System.debug(LoggingLevel.ERROR, 'Try OLI Update');
    update olis;   // list<OpportunityLineItem> olis;
}
catch(System.DMLException dex)
{
    System.debug(LoggingLevel.ERROR, 'Error on OLI Update');
    System.debug(LoggingLevel.ERROR, '\nMessage: ' + dex.getMessage() +
                                     '\nCause: ' + dex.getCause() +
                                     '\nLine Number: ' + dex.getLineNumber() +
                                     '\nStack Trace: ' + dex.getStackTraceString());
}

I placed debug statements all over the place. As last line in my OLI trigger I have a debug statement which outputs the error-free run through of this trigger execution. It is output twice as the trigger runs on both, before and after update. I get those two debug outputs in my log. I also put a debug statement in the first line of my Opportunity trigger. This Opportunity debug statement will not appear in my log as the error is thrown prior to getting there. So I don't even have a chance at preventing the recursive execution.

My OLI trigger should not have an influence as well because it only checks if the OLI(s) may be altered (by querying the opp and its related activities, attachments and OLIs) and throw an error if certain criteria are met.

I did have a Workflow on OLI which updated a field on OLI once a certain criteria on OLI was true. Deactivating that did not help either (because I know that one may cause the parent opportunity to update).

Here's the log:

16:06:52.542 (19542567801)|USER_DEBUG|[21]|ERROR|OLI Trigger seems to have run through without problems
16:06:52.542 (19542629821)|CODE_UNIT_FINISHED|OLITrigger on OpportunityLineItem trigger event AfterUpdate for {...}
16:06:52.604 (19604085441)|USER_DEBUG|[170]|ERROR|Error on OLI Update
16:06:52.604 (19604306394)|USER_DEBUG|[171]|ERROR|
Message: Update failed. First exception on row 0 with id 00kM0000007gX3gIAE; first error: SELF_REFERENCE_FROM_TRIGGER, Object (id = 006M000000CXrL9) is currently in trigger OpportunityTrigger, therefore it cannot recursively update itself: []
Cause: null
Line Number: 166
Stack Trace: Class.OpportunityHandlerDebitor.processUpdate: line 166, column 1
Class.OpportunityHandlerDebitor.handle: line 51, column 1
Class.TriggerTemplate.TriggerManager.runHandlers: line 122, column 1
Trigger.OpportunityTrigger: line 49, column 1

(I have to track debug statements on loggingLevel.ERROR because log size limit was reached with anything higher...)

I am really clueless on how to solve this issue...

0

You must log in to answer this question.