Ensure Clean Data Through Zip Code Validation

There are 41,702 zip codes in the United States and over 850,000 more when you add in Canada. Unfortunately, this is the sort of data where precision is key. As Salesforce experts, we encounter new ways to use data to streamline business efficiency every day. Let’s cover how zip code validation will ensure your team is accurately inputs data with a few simple steps.

Importing a Zip Code Database Object

To get started, a custom object is required in order to populate zip code records which will be used for reference. Depending on the zip code database you have access to or download from, the data points given may vary. Zip-codes.com is one site where you can receive this type of database free of charge. Let’s assume that the table we use has the following metrics, which need to correspond to fields in Salesforce.

Zip Code





Once you’ve created your Zip Code object with the fields mentioned above, you can load in your zip code data as records into your new object. The following is a sample version of what a zip code CSV would contain.

Setting up a Validation Rule

Once your zip code records are loaded, you can then write a simple Validation Rule to reference your zip code records to verify that a zip code exists. The following is the format of the VLOOKUP function, and how it would be used in this context.

VLOOKUP(field_to_return, field_on_lookup_object, lookup_value)

Field_to_return – This is the field you would use to search and index on. Like finding a folder in a cabinet that contains information

Field_on_lookup_object – This is the specific field on that record that you want to reference, in our case return and lookup values are the same

Lookup_value – This is the field you want to match, on the object you are validating.

In this example, we are validating that a zip code exists based on the name of the zip code, against the BillingPostalCode field on Account to make sure the account’s zip code is valid.

Remember to use the $ObjectType resource, as you are not referencing a specific relationship or record

BillingPostalCode != VLOOKUP( $ObjectType.Zip_Code__c.Fields.Name , $ObjectType.Zip_Code__c.Fields.Name, BillingPostalCode )

Once activated, this validation rule will prevent a user from entering a zip code that does not exist in our Zip Code object as a record.

Common Use Cases

Now that we know how zip code validation is set up, let’s talk about some use cases. While preventing invalid data is a great and easy use case for leveraging a zip code database, the data can be used in others as well, such as:

Distance Calculation – If you need an easy way of searching for stores within a certain radius of a specific zip code, you can easily do this with having a table of zip codes available

Zip Code Based Lead/Territory Assignment – Some companies have very granular distribution systems down to the zip code level. Use this table to reference in lead assignment processes or territory assignment processes

Custom Map Visuals – Levering the lightning design system and your zip code table to easily render maps that look appealing to your users

Final Thoughts

You are now ready to set up zip code validation are aware of its common uses. As with all our services, we strive to make the process straightforward and will work with you at each step. As Salesforce growth experts, we’ll continue to provide valuable insights so you can customize how your team uses the platform.

If you’d like to elevate your skillset and make meaningful improvements to your organizational workflow, join our Salesforce Platform Configuration and Administration Essentials Course. This course will enable you to take on difficult processes like this should any arise.

Elliot Hebert, Senior Salesforce Consultant

about the author

Elliot Hebert

Elliot Hebert is a Senior Consultant with OpFocus. He’s been consulting in the Salesforce space for 7 years, with experience in many industries, and several of Salesforces product offerings. He uses his experience to help businesses transform their sales, marketing, and service platforms and gain control of their success.