You need to sign in to do that
Don't have an account?
sarahdev
Parsing Street Addresses?
I need to know what syntax to use to parse the street number out of the standard street address field in a trigger. I only need up to the space in my custom field.
Any help would be greatly appreciated.
All Answers
For non PO box addresses (you'd have to check that separately):
Thanks!, would this be right:
Trigger AddressMapNonStandardFields on Account(before insert,before update){
For(Account a:Trigger.new){
if (a.AccountSource == 'Data.com' && Trigger.isBefore && Trigger.isInsert)
// Will only run this is a data.com record and if it is a NEW record
a.Billing_Street_Number__c= a.BillingStreet.split(' ',2)[0]; // Split by "space", take the first result.;
a.Billing_Street_Name__c=a.BillingStreet;
a.Billing_City__c=a.BillingCity;
a.Billing_State_ABB__c=a.BillingState;
a.Billing_Zip_Code__c=a.BillingPostalCode;
}
}
When I put this in the developer console, the line is highlighted in pink but with no problems. When I try to manally insert an Account, it does not parse the number out of the street address, it doesn't copy anything into the Billing_Street_number__C field.
Any suggestions?
I finally got this working, thanks so much for all your help. It was a error on my end not the person that posted the solution. Here it is.
trigger
AddressMapNonStandardFields on Account(before insert) {
For(Account a: Trigger.new) {
if (a.AccountSource == 'Data.com' && Trigger.isInsert)
// Will only run this is a data.com
record and if it is a NEW record
//Map the standard salesforce billing address fields to my custom fields
{ a.Billing_Street_Number__c = a.BillingStreet.split(' ',2)[0];
a.Billing_Street_Name__c = a.BillingStreet.split(' ',2)[1];
a.Billing_City__c = a.BillingCity;
a.Billing_State_ABB__c = a.BillingState;
a.Billing_Zip_Code__c = a.BillingPostalCode;
}
}
}
Warning: it's pretty ugly, but this actually worked for me:
IF(
NOT(ISNUMBER(MID(BillingStreet,1,1))),
BillingStreet,
IF(
NOT(ISNUMBER(MID(BillingStreet,2,1))),
RIGHT(BillingStreet, LEN(BillingStreet)-1),
IF(
NOT(ISNUMBER(MID(BillingStreet,3,1))),
RIGHT(BillingStreet, LEN(BillingStreet)-2),
IF(
NOT(ISNUMBER(MID(BillingStreet,4,1))),
RIGHT(BillingStreet, LEN(BillingStreet)-3),
IF(
NOT(ISNUMBER(MID(BillingStreet,5,1))),
RIGHT(BillingStreet, LEN(BillingStreet)-4),
IF(
NOT(ISNUMBER(MID(BillingStreet,5,1))),
RIGHT(BillingStreet, LEN(BillingStreet)-4),
BillingStreet
)
)
)
)
)
)