You need to sign in to do that
Don't have an account?
Gabe Rothman
Too many future calls error on lead conversion trigger, any help appreciated :-)
Hey all, I am pretty new to APEX, and I have built a lead conversion trigger, which is causing a "Too many future calls" error. Based on my investigation it looks like I need to bulkify the service class that I am calling in the trigger, but I haven't been able to figure out the correct synatx. Here is the class:
I am pretty sure that I need to move the following outside of the for loop, but I am not sure how to do it.
LeadStatus convertStatus = [SELECT Id, MasterLabel FROM LeadStatus WHERE IsConverted=true LIMIT 1];
lc.setConvertedStatus(convertStatus.MasterLabel);
Database.LeadConvertResult lcr = Database.convertLead(lc);
System.assert(lcr.isSuccess());
Any help greatly appreciated. Thanks!
public with sharing class ConvertLeadOnActiveService { public static void convertLead(list<lead> convertList) { for (Lead lead : convertList) { if (lead.isConverted == false && lead.State__c == 'Active'){ Database.LeadConvert lc = new Database.LeadConvert(); lc.setLeadId(lead.Id); String oppName = lead.Company; lc.setOpportunityName(oppName); LeadStatus convertStatus = [SELECT Id, MasterLabel FROM LeadStatus WHERE IsConverted=true LIMIT 1]; lc.setConvertedStatus(convertStatus.MasterLabel); Database.LeadConvertResult lcr = Database.convertLead(lc); System.assert(lcr.isSuccess()); } } } }
I am pretty sure that I need to move the following outside of the for loop, but I am not sure how to do it.
LeadStatus convertStatus = [SELECT Id, MasterLabel FROM LeadStatus WHERE IsConverted=true LIMIT 1];
lc.setConvertedStatus(convertStatus.MasterLabel);
Database.LeadConvertResult lcr = Database.convertLead(lc);
System.assert(lcr.isSuccess());
Any help greatly appreciated. Thanks!
NOTE: This code has not been tested to compile and may contain typographical errors
All Answers
NOTE: This code has not been tested to compile and may contain typographical errors
Please don't use future or DML,SOQL,describe inside the loop just create a list for the Object let say Account and Contact and insert those list outside the loop to avoid such kind of exception
Please mark my answer as a solution to your question if it solves your problem.
"Save error: Illegal assignment from LIST<Database.LeadConvertResult> to Database.LeadConvertResult"
Any suggestions?