Showing posts with label Validation Rule. Show all posts
Showing posts with label Validation Rule. Show all posts

Wednesday, November 4, 2020

Opportunity must have products to close the opportunity validation rule in salesforce

 Below validation rules fires when you are trying to close the opportunity without opportunity products.

Validation Rule:


AND (
CASE( StageName,
"Closed Won", 1,
0) = 1,
NOT(HasOpportunityLineItem)
)

Output:
Try to close the opportunity without products it will show an error message.





Thursday, February 6, 2020

How to restrict the record edit access using validation rule in salesforce

Assume once the account record is created other users can edit the record except for system administrator and record owner.

Validation Rule
AND( 
    NOT(ISNEW()),
    NOT(OR($Profile.Name == 'System Administrator', $User.Id == OwnerId))
)

above validation rule throws an error if any other user tries to edit the record.

Monday, February 18, 2019

How to fire validation rule only in update operation?


This post explains how to fire the validation rule in the update operation.
Use NOT(ISNEW()) function it will stop the validation rule fire in the insert operation.
Example:
AND (
  NOT(ISNEW()),
  ISCHANGED(Phone)
)
above validation rule will fire only an update operation.


Monday, August 6, 2018

How To Check Active Validation Rules Based On Selected Object Using SOQL

If You want to Check Active Validation Rules on selected Object.
Use Below Simple SOQL Query, This Query Fetch the Active Validation Rule on a Your Select-Object.
SOQL Query:
Select id,Active,Description,EntityDefinition.DeveloperName,ErrorDisplayField,ErrorMessage From ValidationRule where EntityDefinition.DeveloperName='<Object Name>' and active = true
Note: Use Tooling API while Querying.
If You are Using Developer Console

Check the Screen Shot For More Information


Let Us Know If  You Have Any Queries.

Happy Learning!!