function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion

How to show Country, State, County If you have only Zip Code field on the record?

Hello Developers!

I have one of object which has thousands of records with all of them having a Zip Codes (Mostly US). Now, how do I create a formulas to populate Country, City, State, and County.

I have found one excel file online which has all of the US states, Zip, county, City infomation.

I know this is goes somewhere around creating a Custom Setting in salesforce and import all the data from excel file but I am wondering how to go about it?

Should I create a LIST setting type or Hierarchy setting type? Which one suits best in my case?

Thank you for your help!
I would do it very simply without code, custom settings or anything
I would create an object (example named Zip Codes) and import excel you mentionned, then make a lookup on record which has missing info to the new object called Zip code.

Then once lookup value is filled in (zip code)  a Simple PB or WF can populate from lookup record into the record u need info

Hope it helps


Thank you for the response! But that way I am going to have to make so many different If and Else statements.

There are around 40,000 different zipCodes in USA so its going to be 40,000 different If and Else statements.

Anyway, I had approach this issue with the Apex Code though.. Which I am posting in next post. But again, thank you for the response!
If Anyone is till looking this post then this is a code I have came up with,

Trigger Code:
Trigger FillingInfo On Request__c(Before Insert, Before Update, After UnDelete){
    List<Zip_Code__c> allZipCodeObjRecords = [Select Id, City__c, Country__c, County__c, State__c, Zip_Code__c
                                                        FROM Zip_Code__c LIMIT 50000];
    If(Trigger.IsInsert || Trigger.IsUpdate || Trigger.IsUnDelete)
        For(Request__c req : Trigger.New)
            If(req.Zip_Code__c != Null)
                For(Zip_Code__c EveryZipCodeRecord : allZipCodeObjRecords )
                   If(String.ValueOf(req.Zip_Code__c) == String.Valueof(EveryZipCodeRecord.Zip_Code__c ))
                       req.City_Trigger_Updated__c = String.ValueOf(EveryZipCodeRecord.City__c);
                       req.Country_Trigger_Updated__c= String.ValueOf(EveryZipCodeRecord.Country__c);
                       req.County_Trigger_Updated__c= String.ValueOf(EveryZipCodeRecord.County__c);
                       req.State_Trigger_Updated__c= String.ValueOf(EveryZipCodeRecord.state__c);

BUT HOWEVER, My goal for this post is to get myself more educated upon CUSTOM SETTINGS in salesforce. If anyone has an idea / kowledge then please share and I will mark this question solved/best answered.

Thank you developers!
A pleasure , but not sure you understood what I meant.

Create object Named Zip Codes (or wtv u want) + fields you need for address
Import your excel in that new object, the zip code being the record name 
Let's say object with imcomplete address is the lead object.
Create a look up from Lead to that New Object .
Then create a  Process builder with this formula:
ISCHANGED(Zip_Code__c) <---- lookup field on 'Lead'

The create action to fetch data from lookup record to the lead record

And voila, Done!
I am till not getting it though...

Alright so let's say I have a obejct called "AllUSZips" and in their I have 40,000 records.

Now, in my Lead Object I am creating a look up field correct! How does this going to help me out.

Let's have a four records in "AllUSZips" obj as

Record-1 Zip = 11 and City = MontVille
Record-1 Zip = 22and City = SkyVille
Record-1 Zip = 33and City = NorthVille
Record-1 Zip = 250and City = SouthVille

Now, when I create a record in LEAD object which of those four record I would attach it to??
we need to establish something that says.. Whenever Lead Records comes to the Database and it has a Zip Code != Null THEN --> Go find the similar zip code in "AllUSZips" object's records and get appropriate City and show that city on the Lead Obj.