Showing posts with label validation rule. Show all posts
Showing posts with label validation rule. Show all posts

Saturday, May 7, 2011

Bug (?) with ISNULL() Function in Validation Rules

I tried to setup a simple validation rule today in my sandbox to enforce the presence of a value in a Lookup field.

My first attempt for the error formula was:
ISNULL( Source_Program__c )

However, this turned out not to work at all. Whether a value was in the field or not, the formula never generated a validation error.

Then, I switched over to an even more basic formula:
Source_Program__c = null

This worked like a charm. Am I missing something here?

Monday, December 13, 2010

Enforcing Record Name Convention in Salesforce without Apex

One can enforce a record naming convention with a few steps in Salesforce, sans Apex!
  1. Create a formula field called Expected Name with a formula that evaluates to the name you want to see.
  2. Create a validation rule called "Name Expected" with error formula: Name != Expected_Name__c

Enforcing Record Name Uniqueness in Salesforce without Apex

I discovered today that it is possible to enforce record name uniqueness in Salesforce without using any Apex code!

All that is needed is a simple validation rule with the error formula set to the following:
Name = VLOOKUP( $ObjectType.Object.Fields.Name , $ObjectType.Object.Fields.Name , Name ) && Id <> VLOOKUP( $ObjectType.Object.Fields.Id , $ObjectType.Object.Fields.Name , Name )

However, there doesn't seem to be an easy to to perform a case-sensitive comparison in the formula builder. Another thought would be to do the following to enforce name uniqueness:
  1. Create a text field called Unique Name on the object, and add the case-sensitive uniqueness constraint.
  2. Create a workflow field update called Unique Name that just sets Unique_Name__c to Name.
  3. Create a workflow rule called Set Unique Name that's triggered every time a record is created or updated.
  4. Activate the workflow rule.

Last edited on 8/10/2011.