You need to sign in to do that
Don't have an account?
Dbjensen
Simple Class - Apex CPU time limit exceeded
Hello - I have small class that looks for an existing lead that matches a newly inserted lead. If a matching lead is found, it checks a box called Resubmitted. If I dataload any more than 10 records, I get a CPU time limit error. What do I need to do to fix this code so I load leads in bulk?
Class:
Class:
- public class ResubmittedLead {
- public static void resubmittedLead(List<Lead> reLead){
- List<Lead> leadList = new List<Lead>();
- //Lead Maps
- Map<String, String> mapOfLeadId = new Map<String, String>();
- for (Lead ld : reLead){
- mapOfLeadId.put(ld.LastNameStreetAndZipCode__c, ld.Status);
- }
- //Search for existing lead
- for(Lead existingLd : [Select Id, Status FROM Lead WHERE LastNameStreetAndZipCode__c IN :mapOfLeadId.keySet()
- AND Duplicate__c = false]){
- existingLd.Resubmitted__c = true;
- leadList.add(existingLd);
- }
- update leadList;
- }
- }
- if (Trigger.IsAfter) {
- if (Trigger.isInsert){
- for(Lead ld:Trigger.new){
- if(ld.Duplicate__c == true){
- ResubmittedLead.resubmittedLead(Trigger.new);
- }
- }
- }
- }
All Answers