实际上,我正在尝试将Area_c
自定义对象(邮政编码)中的字段放入引导对象自定义字段中Area_c
。所以,我已经编写了一些代码,但是还有其他方法可以编写它或对这段代码进行一些优化。
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;
}
}
}