This is my trygger on Opportunity object.
trigger AutoProductupdate on Opportunity ( before update,after update) {
static boolean already=false;
if (already==false){
for(Opportunity newOppt : Trigger.new){
if (trigger.isAfter){
if (newOppt.Pricing_Tears__c.trim()=='Gigabyte'){
SYSTEM.DEBUG('update');
Automations.UpdateOpportunityLineItems(newOppt);
//Action of the called function:
//DELETE OPPORTUNITY LINE ITEM SCHEDULES FOR ALL THE PRODUCTS
// UPDATE OPPORTUNITY LINE ITEM
Automations.SheduleOpportunityLineItem(newOppt);
//Action of the called function:
// CREATE OPPORTUNITY LINE ITEM SCHEDULES FOR ALL THE PRODUCTS
}
}
}
already=true;
}
}
I am working with opportunity product and opportunity product schedules. In the debug log i see that the trigger is working recursively (It 's printed 15 times the string 'update' with the system.debug).
The error message:
execution of AfterUpdate caused by: System.DmlException: Delete failed. First exception on row 0 with id 00oL0000000acVqIAI; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, AutoProductupdate: maximum trigger depth exceeded Opportunity trigger event AfterUpdate for [006L0000003EUVZ] Opportunity trigger event AfterUpdate for [006L0000003EUVZ] Opportunity trigger event AfterUpdate for [006L0000003EUVZ] Opportunity trigger event AfterUpdate for [006L0000003EUVZ] Opportunity trigger event AfterUpdate for [006L0000003EUVZ] Opportunity trigger event AfterUpdate for [006L0000003EUVZ] Opportunity trigger event AfterUpdate for [006L0000003EUVZ] Opportunity trigger event AfterUpdate for [006L0000003EUVZ] Opportunity trigger event AfterUpdate for [006L0000003EUVZ] Opportunity trigger event AfterUpdate for [006L0000003EUVZ] Opportunity trigger event AfterUpdate for [006L0000003EUVZ] Opportunity trigger event AfterUpdate for [006L0000003EUVZ] Opportunity trigger event AfterUpdate for [006L0000003EUVZ] Opportunity trigger event AfterUpdate for [006L0000003EUVZ] Opportunity trigger event AfterUpdate for [006L0000003EUVZ] Opportunity trigger event AfterUpdate for [006L0000003EUVZ]: []: Class.Automations.UpdateOpportunityLineItems: line 70, column 1
Which is the problem?
How can avoid this?