function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Carrlos BoydCarrlos Boyd 

VR to prevent opening a new record without certain fields populated

I need help with a validation rule to prevent opening a new record based on the following parameters:
 
IF picklist value of Field1__c = "XXXX" or "YYYY"
THEN
Field2__c cannot be NULL

In other words, Field2__c must have a value (it's a user lookup) when Field1__c is a certain picklist value (there are two options in this case) in order for a record to be created.
Best Answer chosen by Carrlos Boyd
ShubhopediaShubhopedia
Also, if field 1 is a picklist then it would give an error ideally since you are comparing a picklist value to text, so in that case following should be fine:

AND(
  OR(
     TEXT(FIELD1__c) = 'XXXX',
     TEXT(FIELD1__c) = 'YYYY'
  ),
  Field2__c=NULL
)

Cheers.

All Answers

ShubhopediaShubhopedia
Following Validation Rule:

AND(
  OR(
     FIELD1__c='XXXX',
     FIELD1__c='YYYY'
  ),
  Field2__c=NULL
)

Let me know if this helps.
Thanks
ShubhopediaShubhopedia
Also, if field 1 is a picklist then it would give an error ideally since you are comparing a picklist value to text, so in that case following should be fine:

AND(
  OR(
     TEXT(FIELD1__c) = 'XXXX',
     TEXT(FIELD1__c) = 'YYYY'
  ),
  Field2__c=NULL
)

Cheers.
This was selected as the best answer
Carrlos BoydCarrlos Boyd
The one with TEXT worked perfectly. The other returned an error based on the fields being picklists. 

Thanks!!