Actually, I am trying to get Area_c
field from custom object(Zip Codes) into the lead object custom field Area_c
. So, I have written some of the code but is there any other way to write it or get some optimization of this code.
trigger OpportunityPriceBook on Lead (before insert) {
List<String> zipList = new List<String>();
for(Lead lead : Trigger.new){
zipList.add(lead.PostalCode);
}
List<Zip_Code__c> zipCodeList = [Select Id, Name, City__c, Area__c from
Zip_Code__c WHERE Name IN : zipList];
for(Lead leads : Trigger.new){
for(Integer i =0 ; i < zipCodeList.size(); i++)
{
leads.Area__c = zipCodeList.get(i).Area__c;
leads.City = zipCodeList.get(i).City__c;
break;
}
}
}