You need to sign in to do that
Don't have an account?
Error: Maximum trigger depth exceeded
HI All,
I am getting an error Maximum trigger depth exceeded .Please help.
trigger UpdateContact on Case (before insert,after insert) {
if(Trigger.isBefore){
if ((Trigger.new.size() == 1)&&(trigger.new[0].Source_ID__c !=null)){
list<Contact> con = new list<Contact>([Select c. Employee_ID__c, c.Id, c.Email From Contact c where c.Employee_ID__c =: trigger.new[0].Source_ID__c]);
if(con.size()>0){
system.debug('----con[0].Id-------'+con[0].Id);
trigger.new[0].ContactID = con[0].Id;
system.debug('-------trigger.new[0].ContactID-------'+trigger.new[0].ContactID);
}
}
}
if(Trigger.isAfter){
list<Case> clist = new list<Case>();
for(Case c:trigger.new){
clist.add(new Case( Tool__c= c.Tool__c,Source_ID__c= c.Source_ID_2__c,));
}
insert clist;
}
}
u are going in to infinete loop..write the same logic in a class and stop the process once ur custom insertion is done using static variable....
Thanks for your reply.Can you plss modify my trigger
this is the sample check it out and try
trigger ProcessAccount on Account (before insert, before update) {
Set<String> uniqueNames = new Set<String>();
if (!ProcessorControl.inFutureContext) {
for (Account a : Trigger.new)
uniqueNames.add(a.UniqueName__c);
if (!uniqueNames.isEmpty())
AccountProcessor.processAccounts(uniqueNames);
}
}
class
public class AccountProcessor {
@ublic static void processAccounts(Set<String> names) {
// list to store the accounts to update
List<Account> accountsToUpdate = new List<Account>();
// iterate through the list of accounts to process
for (Account a : [Select Id, Name From Account where UniqueName__c IN :names]) {
// ... do your account processing
// add the account to the list to update
accountsToUpdate.add(a);
}
ProcessorControl.inFutureContext = true;
// update the accounts
update accountsToUpdate;
}
}