Ask Search:
Praveen JaswalPraveen Jaswal 

vlookup Function

Hi All - Can anybody please let me know how to use vlookup Function in SF. Please provide me some examples if you have.

I want to use it to Validate Zip/Postal Code, State and Country Fields. I have added a custom object with the details of all the countries, their states and Zip and i am trying to reference this custom object through vlookup function but unable to get this done.

Please suggest.

Thanks & Regards,

Praveen JaswalPraveen Jaswal
I saw this example in the help article but then also unable to get it right.
Amanda K HowellAmanda K Howell
Did you ever get an answer on this?  Based on the way you worded your question I am thinking that the issue may be in how you put your data in for your custom object that the vlookup is supposed to search.  You need a new record for every single Zipcode, State and Country option.  So you can't have a record for every Country and then within those country records have all of their states and zip codes listed.  You have to expand it out and have a record for everything.  In this case it would need to be a record for every zip code since that is the farthest out branch in your line.
Sujit NirkheSujit Nirkhe
First of all clear idea about vlookup, how it works.
Then u will understand vlookup here.(I understood vlookup in this manner. So u can try it.)
M NaveenM Naveen
vlookup function is used to bring relevent value to that record from another record automatically
Praveen Jaswal (Sops)Praveen Jaswal (Sops)
Vlookup in SF can only be used to compare the values we can't pull out values as we do in excel.

This is how i applied the validation.

AND((OR(Country = "USA",Country = "Australia",Country = "Canada")), VLOOKUP( $ObjectType.State_Abbreviation__c.Fields.Country__c,
State )<> Country
Avinash KaltariAvinash Kaltari
Hi Praveen,

Just to confirm and get it right, the formula you have written return TRUE only if the selected State does NOT belong to either USA/Canada or Australia. 

Is that correct?
Derhyk DoggettDerhyk Doggett

I managed to get behaviour similar to excel VLOOKUP via apex trigger.

Example below.

The example uses Product_Code__c on Asset History object to get the Product Description from the Product object. It was not acceptible to traverse Asset to get the Product details from the Asset as it could be different per Asset History Entry.

trigger productPopulate on Asset_History__c (before insert, before update) {

    Map <String,String> ProductMap = new Map <String,String>();

    List<Product2> ProductList = [Select ProductCode, Name from Product2];

    for (Product2 p : ProductList){
        ProductMap.put (p.ProductCode, p.Name);

    for (Asset_History__c ah :{
        ah.Product__c = ProductMap.get(ah.Product_Code__c);