+ Start a Discussion
peter.olivier1.3897275862899202E12peter.olivier1.3897275862899202E12 

Apex Trigger issue: Edit/Save Phone number on Contact page

I'm using an Enterprise instance and am getting the following error ever time we try to edit or save a Phone number (Standard Field) on the Contact Object (Standard Object). The error is present even when entering valid us numbers (no dashes, letters, etc.)

Error:Apex trigger updateCustomObjects caused an unexpected exception, contact your administrator: updateCustomObjects: execution of AfterUpdate caused by: System.LimitException: Attempted to schedule too many concurrent batch jobs in this org (limit is 5).: Trigger.updateCustomObjects: line 73, column 1
Anil SavaliyaAnil Savaliya
Hey Peter,

Your massage says,You have UpdateCustomeobject trigger in contact object,and In trigger code line 73 trying to invoke more than 5 batch same time.
peter.olivier1.3897275862899202E12peter.olivier1.3897275862899202E12
Thanks Andys323! I understood that much. However - now what? Why would this start happening all of a sudden? Can I raise my limit? How can I control my batch jobs? Is this a common issue?
Anil SavaliyaAnil Savaliya
No,You can not rise limit.Can you pasta code for trigger Updatecustomeobject trigger? This not happen suddenly? You have quied batch same time more than five.
peter.olivier1.3897275862899202E12peter.olivier1.3897275862899202E12
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 *73*74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 trigger updateCustomObjects on Contact (after update) { Map updatedContacts = new Map(); List lstContactId = new List(); for(Integer i = 0; i < Trigger.new.size(); i++) { if ((Trigger.old[i].Phone != Trigger.new[i].Phone) || (Trigger.old[i].Email != Trigger.new[i].Email)) { updatedContacts.put(Trigger.new[i].Id, Trigger.new[i]); lstContactId.add(Trigger.new[i].Id); } } /* //select IDs of all Meeting Attendees where ContactID is the same as the ID of the current Contact List attendee = [SELECT ID, Contact__c FROM Meeting_Attendees__c WHERE Contact__c IN :updatedContacts.keySet()]; //update Phone and Email for all Meeting Reports having IDs as above with the new values for(integer i = 0; i < attendee.size(); i++) { attendee[i].Phone__c = updatedContacts.get(attendee[i].Contact__c).Phone; attendee[i].Email__c = updatedContacts.get(attendee[i].Contact__c).Email; } //if(!attendee.isEmpty()) //{ // update attendee; //} List> lstSplittedAttendee = new List>(); List lstTemp = new List(); for(Integer i=0 ;i < attendee.size();i++) { if(lstTemp.size() == 100) { lstSplittedAttendee.add(lstTemp); lstTemp = new List(); } else { lstTemp.add(attendee[i]); } } if(lstTemp.size() > 0 ) lstSplittedAttendee.add(lstTemp); if(!lstSplittedAttendee.isEmpty()) { for(Integer i =0 ; i < lstSplittedAttendee.size() ; i++) { update lstSplittedAttendee[i]; } } */ /* Start - Changes Made here on 10th March */ String strContactIds = ''; for(Integer i = 0 ;i < lstContactId.size(); i++) { if(i == 0 && lstContactId.size() > 1) strContactIds = '(\'' + lstContactId[i] + '\''; else if( i > 0 && i != lstContactId.size()-1 ) strContactIds = ' , \'' + lstContactId[i] + '\''; else if( i > 0 && i == lstContactId.size()-1 ) strContactIds = ' , \'' + lstContactId[i] + '\')'; else if(i == 0 && lstContactId.size() == 1) strContactIds = '(\'' + lstContactId[i] + '\')'; } System.debug(' $$$$$$$$$ strContactIds == ' + strContactIds ); if(strContactIds != '') { String strQuery = 'SELECT ID, Contact__c FROM Meeting_Attendees__c WHERE Contact__c IN ' + strContactIds; System.debug(' $$$$$$$$$ strQuery == ' + strQuery ); clsBatchAttendeeUpdate bc = new clsBatchAttendeeUpdate(strQuery,updatedContacts); Database.executeBatch(bc, 200); } /* End - Changes Made here on 10th March */ //select IDs of all Contact Relationships where ContactID is the same as the ID of the current Contact List relationship = [SELECT ID, Contact__c FROM Relationship__c WHERE Contact__c IN :updatedContacts.keySet()]; //update Phone and Email for all Relationships having IDs as above with the new values for(integer j = 0; j < relationship.size(); j++) { relationship[j].Phone__c = updatedContacts.get(relationship[j].Contact__c).Phone; relationship[j].Email__c = updatedContacts.get(relationship[j].Contact__c).Email; } if(!relationship.isEmpty()) { update relationship; } //select IDs of all Project Members where ContactID is the same as the ID of the current Contact List members = [SELECT ID, Project_Member__c FROM Project_Members__c WHERE Project_Member__c IN :updatedContacts.keySet()]; //update Phone and Email for all Relationships having IDs as above with the new values for(integer k = 0; k < members.size(); k++) { members[k].Phone__c = updatedContacts.get(members[k].Project_Member__c).Phone; members[k].Email__c = updatedContacts.get(members[k].Project_Member__c).Email; } if(!members.isEmpty()) { update members; } }
Anil SavaliyaAnil Savaliya
Hey Peter,

See this part in your code.

if(strContactIds != '') { String strQuery = 'SELECT ID, Contact__c FROM Meeting_Attendees__c WHERE Contact__c IN ' + strContactIds; System.debug(' $$$$$$$$$ strQuery == ' + strQuery ); clsBatchAttendeeUpdate bc = new clsBatchAttendeeUpdate(strQuery,updatedContacts); Database.executeBatch(bc, 200); }

That mean,

In your instance Now have more than 1000 Meeting attendees record,and It's firring batch 5 times concurrently.As salesforce limit ,You can't  quied more that 5 active batch in salesforce.

You can see invoked batch in setup-Admin setup-Moniterning-Apex job

Please write secedulade batch apex,to resolve this issue ,Comment code i pasted above.
Saravanan @CreationSaravanan @Creation
Hi Peter,

This below post will explain you how to resolve yours suitiation

https://help.salesforce.com/HTViewSolution?id=000182449&language=en_US

Thanks,