You need to sign in to do that
Don't have an account?
Problem: Max trigger depth exceeded
trigger PayHist_insert_Under_Agr_ProcessUnit on UOP_Royalty_Payment_History__c (before insert) { set<String> agid=new set<String>(); set<id> pid=new set<id>(); id ppid; for(UOP_Royalty_Payment_History__c UOP:Trigger.new) { ppid=UOP.Process_Unit__c; agid.add(UOP.Aggregation_Group__c); pid.add(UOP.Process_Unit__c); } Process_unit__c pp=[select id,name,Aggregation_Group__r.id from Process_Unit__c where id=:ppid]; id aagid=pp.Aggregation_Group__r.id; UOP_Aggregation_Group__c aa=[select id,name from UOP_Aggregation_Group__c where id=:aagid]; id prid=aa.id; List<Process_Unit__c> pc=new List<PRocess_Unit__c>(); pc=[select id,name from Process_Unit__c where Aggregation_Group__r.id=:prid and id!=:ppid]; System.debug('total PU'+pc.size()); List<UOP_Royalty_Payment_History__c> insrtpay=new List<UOP_Royalty_Payment_History__c>(); UOP_Royalty_Payment_History__c inpay=new UOP_Royalty_Payment_History__c(); for(Process_Unit__c p:pc) { insrtpay.add(new UOP_Royalty_Payment_History__c(Payment_History_Event__c='Report',Process_Unit__c=p.id)); } System.debug('insrtpay'+insrtpay.size()); if (!insrtpay.isEmpty()){ insert insrtpay; } }
Error Msg:
Error: Invalid Data.
Review all error messages below to correct your data.
Apex trigger PayHist_insert_Under_Agr_ProcessUnit caused an unexpected exception, contact your administrator: PayHist_insert_Under_Agr_ProcessUnit: execution of BeforeInsert caused by: System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, PayHist_insert_Under_Agr_ProcessUnit: maximum trigger depth exceeded UOP_Royalty_Payment_History trigger event BeforeInsert for [new] UOP_Royalty_Payment_History trigger event BeforeInsert for [new, new, new, new] UOP_Royalty_Payment_History trigger event BeforeInsert for [new, new, new, new] UOP_Royalty_Payment_History trigger event BeforeInsert for [new, new, new, new] UOP_Royalty_Payment_History trigger event BeforeInsert for [new, new, new, new] UOP_Royalty_Payment_History trigger event BeforeInsert for [new, new, new, new] UOP_Royalty_Payment_History trigger event BeforeInsert for [new, new, new, new] UOP_Royalty_Payment_History trigger event BeforeInsert for [new, new, new, new] UOP_Royalty_Payment_History trigger event BeforeInsert for [new, new, new, new] UOP_Royalty_Payment_History trigger event BeforeInsert for [new, new, new, new] UOP_Royalty_Payment_History trigger event BeforeInsert for [new, new, new, new] UOP_Royalty_Payment_History trigger event BeforeInsert for [new, new, new, new] UOP_Royalty_Payment_History trigger event BeforeInsert for [new, new, new, new] UOP_Royalty_Payment_History trigger event BeforeInsert for [new, new, new, new] UOP_Royalty_Payment_History trigger event BeforeInsert for [new, new, new, new] UOP_Royalty_Payment_History trigger event BeforeInsert for [new, new, new, new]: []: Trigger.PayHist_insert_Under_Agr_ProcessUnit: line 38, column 1
When i save the record the abover error msg comes up..
Please any one help me out from this issue..
Thank you
Hi santro652,
your trigger is fired when UOP_Royalty_Payment_History__c record is inserted,
but you are also inserting the record of same object inside the trigger.
So whats happening is your trigger is being called from within causing recursion.
Use a static class to avoid Recursion.
All Answers
Hi santro652,
your trigger is fired when UOP_Royalty_Payment_History__c record is inserted,
but you are also inserting the record of same object inside the trigger.
So whats happening is your trigger is being called from within causing recursion.
Use a static class to avoid Recursion.
Thanks Rahul, i will try this and let you know if your solution solved my issue.