How to write validation rules with V-Lookup in Salesforce

//How to write validation rules with V-Lookup in Salesforce
  • Salesforce Validation with vLookup

How to write validation rules with V-Lookup in Salesforce

In this article, we will explore the V lookup function within Salesforce. The first thing which comes to one’s mind on hearing this term is MS-Excel, in which Vlookup is a function that returns a value from a table based on an identifier. Along with many functions, Salesforce also provides the V-Lookup function to meet our business requirements.

V-lookup function is only available in validation rules for custom objects. We cannot use V-lookup for standard objects in Salesforce. Following is the syntax of the function.

V-lookup searches from the lookup object with lookup value. It returns the specified field value on successful match.

  • Field to Return: It is the field that you want to return from the custom object.
  • Field on lookup field: It is a field on the related object that contains a value you want to match.
  • Lookup value: This contains the value, you want to match the record with.

Explained with an example

Consider a business scenario, an organization with name ABC Inc has a custom object called “Property”. Property object stores the information about Land, Apartments, Independent houses etc. organization wants to make sure that there should not be two records with the same property name. If a user tries to create the record with the same name, it should notify the user with a message that “Property with the same name already exists”. This can be achieved using V-lookup function. Let’s see how to create a validation rule using the V-lookup function.

Creating a Validation Rule using V-lookup:

Below are the steps to create validation rule.

  • Navigate to Setup-> Build-> Create-> Objects (or) simply open the object, from the “Expand Quick Access Menu” click on “View validation rules”.
  • Click on “New” button. The following screen will be shown.

Creating a Validation Rule using Vlookup

  • Enter the Rule Name and
  • In the “Error Condition Formula” section, enter the following formula.

  • Here I’m using two V-lookup’s to check two conditions. One is to check whether both the records have the same name and other is to check whether the id’s of the records are different so that an error message can be shown.
  • $Object Type is a global merge field type used to reference objects and values of their fields. As we are comparing the records of the same object, I’ve selected Property as lookup
  • In the First condition V-lookup returns the Property Name(Parameter 1) from lookup object(Parameter 2) by comparing with the current property Name(Parameter 3). In the second condition Vlookup returns the Property Id(Parameter 1) from lookup object(Parameter 2) by comparing with the current property Name(Parameter 3).
  • In the “Error Message” Section, I’ve given the error message as “Property with the same name already exists”.
  • When the Error condition formula evaluates to true, error message will be shown. We can define the location of the error message. It can be shown at the top of the page or it can be shown at the specified field. Here I’m selecting Property Name field as Error location.

Screenshot of Validation Rule Edit

  • Click on save
  • We’ve created a validation rule. Now we’ll check the rule by creating a property with the same name.

Screenshot of created a validation rule

 

  • In the above figure, I’ve tried to create a property with the same Name “Test-A01”. An error message is thrown at the property Name field.

Limitations

Following are the limitations of the solution. These are listed below.

  • 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, 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 function is only available in validation rules.

In this way, you can get the value of field from the custom object using V-lookup function in validation rules.


About us and How we can help

Our team can help you customize and integrated Salesforce as per your business process. Read about our Salesforce Integration Services. Reach out to us for a free assessment of your business needs.

Contact us for a free assessment

Spread the Wisdom
By |2018-10-01T22:21:19+00:00October 1st, 2018|Salesforce|0 Comments

About the Author:

Veon brings best in consulting and integration solutions on Salesforce, SugarCRM, and SAP. It is an innovative company which deals best of the breed solution using integration solutions on the above platforms. making small and medium enterprise become smarter.