You need to sign in to do that
Don't have an account?
ItsJustCode2
How do I bulkify this??? Kudos offered to best advice
I seem to have problems around line 43 where I have my
zipMapState.get(l.postalcode.substring(0,5));
Statement. I was wondering if there is a more efficient way of doing this?? Please help if you can I'd really appriciated it.
Thank you, Steve
zipMapState.get(l.postalcode.substring(0,5));
Statement. I was wondering if there is a more efficient way of doing this?? Please help if you can I'd really appriciated it.
Thank you, Steve
trigger ZipCodeStateCityFix on Lead (before insert, before update) { set<string> left5zips = new set<string>(); String ZipVar; for (lead l: trigger.New) { ZipVar = l.postalcode; if(l.PostalCode != null) { if(l.postalcode.length()>= 5) { if ((l.State == null || l.City == null) && l.postalcode != null) { left5zips.add(l.postalcode.substring(0,5)); } } } } //query the zip_code object to get the zipcode (Name) and zone from the zip code object if(ZipVar != null) { if(ZipVar.length() >= 5) { map<string,string> zipMapState=new map<string,string>(); map<string,string> zipMapCity=new map<string,string>(); for(Zip_Code_Look_up__c z : [Select name, State__c, City__c from Zip_Code_Look_up__c WHERE name IN :left5zips]) { zipMapState.put (z.name, z.State__c); zipMapCity.put (z.name, z.City__c); } for (lead l: trigger.new) { if((l.State == null || l.City == null) && l.postalcode != null) { String State = zipMapState.get(l.postalcode.substring(0,5)); String City = zipMapCity.get(l.postalcode.substring(0,5)); if (State != null) { l.State = State; l.City = City; l.Country = 'USA'; } } if (l.State == null ) { Return; } } }} Return; }
Change you line 43 and 44 with below ones :
String State = '';
String City = '';
if(l.postalcode.llength()= 5)
{
State = zipMapState.get(l.postalcode.substring(0,4));
City = zipMapCity.get(l.postalcode.substring(0,4));
}
else if(l.postalcode.llength()> 5)
{
State = zipMapState.get(l.postalcode.substring(0,5));
City = zipMapCity.get(l.postalcode.substring(0,5));
}
Hopefully It will work for you. Let me know if more information will require.
Thanks,
Vishal
All Answers
Change you line 43 and 44 with below ones :
String State = '';
String City = '';
if(l.postalcode.llength()= 5)
{
State = zipMapState.get(l.postalcode.substring(0,4));
City = zipMapCity.get(l.postalcode.substring(0,4));
}
else if(l.postalcode.llength()> 5)
{
State = zipMapState.get(l.postalcode.substring(0,5));
City = zipMapCity.get(l.postalcode.substring(0,5));
}
Hopefully It will work for you. Let me know if more information will require.
Thanks,
Vishal
String State = '';
String City = '';
if(l.postalcode.length()== 5)
{
State = zipMapState.get(l.postalcode.substring(0,4));
City = zipMapCity.get(l.postalcode.substring(0,4));
}
else if(l.postalcode.length()> 5)
{
State = zipMapState.get(l.postalcode.substring(0,5));
City = zipMapCity.get(l.postalcode.substring(0,5));
}
Thanks,
Vishal