One of my old triggers is beginning to cause Apex CPU Time Limit errors, I was fairly close to this limit when the trigger was first made but since it worked perfectly for so long it was neglected.
The first thing it does it build a Map:
Map<String,Id> comparisonMap = new Map<String,Id>();
for(Lead l : [Select Id, Company, Postcode__c, Landline_Phone__c FROM Lead WHERE isConverted = FALSE AND Check_Lead__c = TRUE]){
IF(l.Company != null){
comparisonMap.put(l.Company.toLowerCase().replace(' ','').replace('-',''), l.Id);
}
IF(l.Postcode__c != null){
comparisonMap.put(l.Postcode__c.replace(' ',''), l.Id);
}
IF(l.Landline_Phone__c != null){
comparisonMap.put(l.Landline_Phone__c.replace(' ',''), l.Id);
}
}
Which is then added to a set for later use:
Set<String> comparisonSet = new Set<String>();
comparisonSet.addAll(comparisonMap.keySet());
Is there a more efficient way of doing this? I think the .toLowerCase() and .replace methods on line 5 are quite taxing on the CPU Time:
comparisonMap.put(l.Company.toLowerCase().replace(' ','').replace('-',''), l.Id);
Any help would be greatly appreciated!