Formula Field and Validation Rule in Salesforce

 


 Formula Field and Validation Rule in Salesforce 


Validation rules:

Validation rules in salesforce contains a formula or expressions that evaluates the data in one or more  fields in a record to meet the standards and returns a value “True” or “False”. Validation rules displays error message to the user when the Condition is “False”.

Validation rules in salesforce contains a formula or expressions that evaluates the data in one or more  fields in a record to meet the standards and returns a value “True” or “False”. Validation rules displays error message to the user when the Condition is “False”. Validation rules in Salesforce are the rules which contains a formula expressions that validates our data and returns a value of “True” or “False.

  • Validation rule contain Formula expressions.
  • It evaluate the data entered by the user.
  • Validation Rule displays error message to user when the enter invalid values.
  • We can create Validation rules in Salesforce for Objects, fields, campaign members etc.


Use the Formula Editor

You can create custom formula fields on any standard or custom object. To start, we’ll create a formula on the Opportunity object. Follow these steps to navigate to the formula editor.

  1. From Setup, open the Object Manager and click Opportunity.
  2. In the left sidebar, click Fields & Relationships.
  3. Click New.
  4. Select Formula and click Next.
  5. In Field Label, type My Formula Field. Notice that Field Name populates automatically.
  6. Select the type of data you expect your formula to return.
    For example, if you want to write a formula that calculates the commission a salesperson receives on a sale, you select Currency. For now, pick Text.
  7. Click Next. You’ve arrived at the formula editor! Time for our tour.



1. The formula editor comes in two flavors:
Simple and Advanced. It’s tempting to use the Simple editor, but we always recommend using the Advanced editor. Advanced doesn’t mean more complicated. It means more tools for you to create powerful formulas.

2. The Insert Field button opens a menu that allows you to select fields to use in your formula. Inserting from this menu automatically generates the correct syntax for accessing fields. 

3. The Insert Operator button opens a dropdown list of the available mathematical and logical operators.

4. The Functions menu is where you view and insert formula functions. Functions are more complicated operations that are preimplemented by Salesforce. Some functions can be used as-is (for example, the TODAY() function returns the current date), while others require extra pieces of information, called parameters. The LEN(text) function, for instance, finds the length of the text you input as a parameter. The formula LEN("Hello") returns a value of 5. 

5. The text area is where you enter your formula. When writing formulas, keep in mind that:

  • Whitespace doesn’t matter. You can insert as many spaces and line breaks as you want without affecting the formula’s execution.
  • Formulas are case sensitive. Pay attention to capitalization of field and object names.
  • When working with numbers, the standard order of operations applies.

6. Once you’ve written a formula, you can use the Check Syntax button to ensure that everything is in working order before saving. If your formula has issues, the syntax checker alerts you to specific problems.


# Validation Rules Fields

FIELDDESCRIPTION
Rule NameUnique identifier of up to 40 characters with no spaces or special characters such as extended characters.
ActiveCheckbox that indicates if the rule is enabled.
DescriptionA 255-character or less description that distinguishes the validation rule from others. For internal purposes only.
Error Condition FormulaThe expression used to validate the field.
Error Message

The message that displays to the user when a field fails the validation rule.

If your organization uses the Translation Workbench, you can translate the error message into the languages Salesforce supports.

Error Location

Determines where on the page to display the error. To display the error next to a field, choose Field and select the field. If the error location is a field, the validation rule is also listed on the detail page of that field. If the error location is set to a field that is later deleted, to a field that is read only, or to a field that isn’t visible on the page layout, Salesforce automatically changes the location to Top of Page.




 Formula Field:  



Formula field Limitation:

  • Formula fields have these limits
  • Formula fields can’t exceed 5,000 bytes when compiled. The compile size is the size of the formula (in bytes) including all of the fields, values, and formulas it references. There is no direct correlation between the compile size and the character limit. Some functions, such as TEXT, DATEVALUE, DATETIMEVALUE, and DATE significantly increase the compile size.
  • You can’t use long text area, encrypted, or Description fields in formulas.
  • The value of a field can’t depend on another formula that references it.
  • You can’t delete fields referenced in formulas. Remove the field from the formula before deleting it.


Resource

 Trailhead Module Link  

 Validation Rule (Salesforce)  


Comments

Popular Posts

Asynchronous Apex in Salesforce : Future Methods

Salesforce Admin Interview Questions and Answers

Apex Triggers in Salesforce

DML - Data Manipulation Language in Apex