VLOOKUP in Salesforce Validation Rule

VLOOKUP in Salesforce Validation Rule

Returns a value by looking up a related value on a custom object similar to the VLOOKUP() Excel function.



  • The field_to_return
    must be an auto number, roll-up summary, lookup relationship,
    master-detail relationship, checkbox, date, date/time, email, number,
    percent, phone, picklist, text, text area, or URL field type.
  • The field_on_lookup_object must be the Record Name field on a custom object.
  • The field_on_lookup_object and lookup_value must be the same data type.
  • If more than one record matches, the value from the first record is returned.
  • The value returned must be on a custom object.
  • You cannot delete the custom field or custom object referenced in this function.
  • This example
    checks that a billing postal code is valid by looking up the first five
    characters of the value in a custom object called Zip_Code__c that
    contains a record for every valid zip code in the US. If the zip code is
    not found in the Zip_Code__c object or the billing state does not match
    the corresponding State_Code__c in the Zip_Code__c object, an error is
    displayed.

    AND(
    LEN(BillingPostalCode) > 0,
    OR(BillingCountry = “USA”,
       BillingCountry = “US”),
    VLOOKUP(
    $ObjectType.Zip_Code__c.Fields.State_Code__c,
    $ObjectType.Zip_Code__c.Fields.Name,
    LEFT(BillingPostalCode,5))

    <> BillingState
    )


    Cheers!!!

    Leave a Reply