+ Start a Discussion
Greg WehnerGreg Wehner 

Validate Entered Moving Zip Code against Service Area Zip Codes

Is there a way to verify a destination zip code a user enters against a list of zip codes from our service area? We only service 50 miles from our main hub, but we still receive a lot of "dead leads" that fall outside of the 50 miles. I would like it if when users enter their destination zip code and hit entered, that the system tell them that we do not service that area (if we don't) and continue on normally if we do. Please let me know. I am a salesforce novice, so please break it down for me. 
Terence_ChiuTerence_Chiu
There are examples of using the vlookup function to check against zip code validility. It involves creating a custom object of where you can store all valid zip codes.

So for instance if you have a custom object called Valid Zip Codes with the following fields:
Name (store zip codes here)

You can create a validation rule (let's say on the Lead object) with the following formula:
 
LEFT(PostalCode,5) <> VLOOKUP($ObjectType.Valid_Zip_Code__c.Fields.Name, $ObjectType.Valid_Zip_Code__c.Fields.Name, LEFT(PostalCode,5))
The rule checks the records in the Valid Zip Code has a Name that matches to the zip code stored on the Lead field. If a match is not found then the error triggers. You will need to load all the valid zip codes your company services in order for the validation rule to work.

Check the following links for more information:

https://help.salesforce.com/apex/HTViewHelpDoc?id=customize_functions_i_z.htm&language=en_US#VLOOKUP

http://developer.force.com/cookbook/recipe/validating-data-based-on-fields-in-other-records


 
Greg WehnerGreg Wehner
Thanks for the reply. So, if I create a custom object called "Valid Zip Codes" which would need to be tied to a custom field for the destination zip code, would that alter the code above? Does the custom destination zip code identifier replace the "PostalCode" in the formula above? Where do I put the list of valid zip codes within my custom object? Does the formula above get entered in the custom object or the custom field?
Terence_ChiuTerence_Chiu
Replace postalcode with whatever field your users are using to input destination zip code currently.

Replace any instances that references $ObjectType.Valid_Zip_Code__c.Fields.Name with
$ObjectType.Valid_Zip_Code__c.Fields.<whatever you have named the field to store valid zip codes in the custom object >

The formula is used to create a Validation Rule against the object where your users are entering destination zip codes. Here are some info and examples of validation rules you can reference.

https://help.salesforce.com/apex/HTViewHelpDoc?id=fields_useful_field_validation_formulas.htm&language=en

https://help.salesforce.com/HTViewHelpDoc?id=fields_about_field_validation.htm