You need to sign in to do that
Don't have an account?
uma52551.3972270309784705E12
Using Substring(0,5) for Zipcode Apex Trigger
Hi All,
String zipcode1 = a.BillingPostalCode.substring(0,5);
if(a.BillingPostalCode!=NULL&&countyMap.containsKey(zipcode1)) {
a.County__c = countyMap.get(zipcode1).County__c;
}
If I am using the above code it is working for zipcode1 > = 5 but throwing error System.StringException: Ending position out of bounds: for zipcode1<5 i.e; if Zipcode1 = 32809- it is updating the county as Orange
if Zipcode1 = 3280 it is throwing the above error on the account page.
Can any one help me how to avoide this error on account page.
Thanks,
String zipcode1 = a.BillingPostalCode.substring(0,5);
if(a.BillingPostalCode!=NULL&&countyMap.containsKey(zipcode1)) {
a.County__c = countyMap.get(zipcode1).County__c;
}
If I am using the above code it is working for zipcode1 > = 5 but throwing error System.StringException: Ending position out of bounds: for zipcode1<5 i.e; if Zipcode1 = 32809- it is updating the county as Orange
if Zipcode1 = 3280 it is throwing the above error on the account page.
Can any one help me how to avoide this error on account page.
Thanks,
if (a.BillingPostalCode.length() >= 5)
zipcode1 = a.BillingPostalCode.substring(0,5);
else
zipcode1 = a.BillingPostalCode.substring(0,4);
Please try this
All Answers
Try this and let me know it will work or not.
string zipcode1 = a.BillingPostalCode.substring(0,4);
if (a.BillingPostalCode.length() >= 5)
zipcode1 = a.BillingPostalCode.substring(0,5);
else
zipcode1 = a.BillingPostalCode.substring(0,4);
Please try this