I got the following email: Sandbox: Developer script exception from
ContactTrigger: System.LimitException: Too many futurecalls: 51
Important addition: I do not see that mentioned 50 calls were executed in my HTTP call's handler logs.
Indeed I do some future calls upon contact inserting/updating in the loop, but I don't see so many contacts created in bulk in our Salesforce instance. Actually at the time I received this letter no contacts were created at all.
Here is some code:
trigger ContactTrigger on Contact (after delete, after insert, after undelete, after update, before delete, before insert, before update) {
...
if(tc.isAfter){
// call handler instance to meet new registration requirements
new ContactHelper().execute(tc);
}
}
and the helper
public class ContactHelper extends GenericTrigger {
public override void execute(TriggerContext tc)
{
if (Test.isRunningTest()) {
return;
}
List<Contact> affectedContacts = tc.newList;
if (tc.isInsert) {
for (Contact contact: affectedContacts)
{
if (!contact.Greylist__c) {
updatePartnerPortal(contact.id, 'contact_inserted');
}
}
}
if(tc.isUpdate) {
for (Contact contact: affectedContacts)
{
if (contact.PersonID__c == null && !contact.Greylist__c) {
updatePartnerPortal(contact.id, 'contact_updated');
}
}
}
}
@future (callout=true)
public static void updatePartnerPortal(string contactId, string operationType)
{
// HTTP call
}
}
- It is searchable by the info received in exception email from Sforce;
- Because of your explanation that future calls are enqueued - this was my main confusion, actually.
– Maksim Ramanovich Mar 27 '19 at 12:28