Business Problem:

Some sales teams assign territories based on county in the United States and this requires someone to update the county in Salesforce in order to assign the Lead or Account to the appropriate person. Automating the update to the County based on the Postal Code of an address will eliminate the need for someone to manually update this information.

We have built a free AppExchange solution that will automate this entire process for Leads, Contacts and Accounts. This App Exchange package will lookup the county based on the postal code of the following:

    • Leads – the standard Zip Code field
    • Accounts – the standard Billing Zip Code field
    • Contacts – the standard Mailing Zip Code field

The package contains the following components:

    • Postal Code County Mapping (Custom Object) – this object holds the relationship between the County, State and Postal Code; each record is a single postal code.
    • Postal Code County Mapping (Custom Tab)
    • Postal Code County Mapping (Page Layout)
    • City(Custom Field on Postal Code County Mapping Object) – this is the city of the postal code record
    • State(Custom Field on Postal Code County Mapping Object) – this is the state of the postal code record
    • Postal Code(Custom Field on Postal Code County Mapping Object) – stores the postal code data for each record
    • County(Custom Field on Postal Code County Mapping Object) – this is the county of the postal code record
    • County(Custom Field on Lead Object)
    • Billing County(Custom Field on Account Object)
    • Mailing County(Custom Field on Contact Object)
    • Lead | Update County from Postal Code (Process Builder)
    • Account | Update County from Postal Code (Process Builder)
    • Contact | Update County from Postal Code (Process Builder)
    • Lead | Account | Contact – Update County from Postal code (Autolaunched Flow)

How to Configure the App:

  1. Install the AppExchange package into a sandbox environment.
  2. Go to SetupFlows and Activate the flow called Lead | Account | Contact – Update County from Postal code
  3. Go to Process Builder and Activate all three processes: Account | Update County from Postal Code, Contact | Update County from Postal Code and Lead | Update County from Postal Code
  4. Update field level security for the fields for the necessary profiles.
  5. Go to Leads Page Layouts and add the County field to your Lead page layouts.
  6. Go to Accounts Page Layouts and add the County field to your Account page layouts.
  7. Go to Contacts Page Layouts and add the County field to your Account page layouts.
  8. Use Data Loader to import the records needed for the Postal Code County Mapping object in this file. We cannot guarantee this is the most up to date version of the data, there may be some discrepancies for some zip codes if updates are made. You are responsible for validating the data in the file.
    • If you open the csv file to review it, make sure to reapply the custom format to the postal code column, so the leading zeroes are added. We recommend using the Special format called Zip Code.

That’s it, you are ready to test out the app!

Please Note: If you have other process builders in your org for these objects, you may just want to copy these processes into your existing ones. Salesforce recommends only having one active process per object.

How it Works:

  • The process Lead | Update County from Postal Code is triggered whenever you create a Lead with a value in the Zip Code field or if the value in the Zip Code field is changed. It invokes the flow called Lead | Account | Contact – Update County from Postal code. The process passes three variables into the flow:
    • varObject = “Lead” – this tells the flow which path to choose since we are using the same flow for all three objects
    • varObjectId = the Id of the Lead
    • varPostalCode = the Zip Code of the Lead

  • Here is what the flow looks like:

  • Test it out by updating the zip code to have a value and confirm the County is populating. Then remove the zip code and make sure the value is removed from the County field.

The Account and Contact processes work exactly the same way. Looking forward to hearing any suggestions you may have and let us know if this helped you out!

How it Trigger an Update to Existing Records:

Now you have the automation in place and it is working for all newly created or edited records, but what about the rest of your database? Here are the steps on how to easily trigger an update to all existing Lead records quickly:

  1. Go to Setup | Process Builder and select the process called Lead | Update County from Postal Code
  2. Click Clone to create a new version of the process.
  3. Change the Criteria for Executing Actions = No criteria just execute the actions! and click the Activate button.
  4. Using Data Loader, run an export for all Leads that are in the United States and contain a value in the Zip Code field. Make sure to include the Lead Id in your export.
  5. Click Update in Data Loader for the Lead object and insert the export file you exported in step #4. Make sure to only map the Lead Id.
  6. Go to Setup | Process Builder and select the process called Lead | Update County from Postal Code  you cloned in Step #2. Click the version you installed from the package and Activate it. Delete the version you created in Step #2. Make sure the active version looks like this and has Criteria for Executing Actions = Formula Evaluates to true: