You need to sign in to do that
Don't have an account?
Gus proto
Convert lead trigger cpu limits and bulk api
I am running into cpu limit with this am I am missing somthing? And also how can I adjust the code to avoid harcoding the ID like i did.
Trigger AutoConverter on Lead (after insert,after update) { LeadStatus convertStatus = [ select MasterLabel from LeadStatus where IsConverted = true limit 1 ]; List<Database.LeadConvert> leadConverts = new List<Database.LeadConvert>(); for (Lead lead: Trigger.new) { if (!lead.isConverted ) { Database.LeadConvert lc = new Database.LeadConvert(); lc.setLeadId(lead.Id); lc.setDoNotCreateOpportunity(TRUE); lc.setConvertedStatus(convertStatus.MasterLabel); String leadOwner = lead.OwnerId; if(leadOwner.startsWith('00G')){ Lc.OwnerId = '00535000001ZOZN'; } leadConverts.add(lc); } } if (!leadConverts.isEmpty()) { List<Database.LeadConvertResult> lcr = Database.convertLead(leadConverts); } }
USER u = [Select id from user where name = 'My New Owner'];
then in the look use u.id instead of '00535000001ZOZN'
lc.ownerId = u.id;
All Answers
USER u = [Select id from user where name = 'My New Owner'];
then in the look use u.id instead of '00535000001ZOZN'
lc.ownerId = u.id;