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
Kelly TetlockKelly Tetlock 

Using ISNEW and ISCHANGED to make multiple fields mandatory

Hi,
I am very new to Salesforce and have been struggling with writing a validation rule for a week now and am getting nowhere fast!  Essentially I want 3 fields to become required when data is entered into another field.  When a new Contact is created and an Email address is added to the Contact I want a picklist that will capture the Source of the Email, a date field that will capture when the Email was obtained and a text field that will capture who obtained the Email to become mandatory. On a net new record the rule should only run if an Email address is added.  To make matters even more difficult I will also have Contacts in my system that have been imported from a legacy CRM system.  These Contacts may not have an existing Email address.  I also want this rule to run if an Email is added to one of these existing records, or if the Email address on the existing record is changed and the three required fields I note above are blank.
I started out small with just the following.  The appropriate error message does show, but when I choose a picklist value and try to save the error message won't go away and won't let me save the record.

AND
(OR(ISNEW(),(ISCHANGED(Email)),
ISBLANK(TEXT(Email_Source__c))
))

As I've mentioned, I'm very new to Salesforce and am still trying to understand how this validation function works. Any suggestions would be appreciated.
Best Answer chosen by Kelly Tetlock
RaidanRaidan
Hi Kelly,

I think the formula will look like below (I also included the ISCLONE(), in case the record is cloned). You probably also need to change the field names below since I don't know their real API names.

AND(
   OR(ISNEW(), ISCLONE(), ISCHANGED(Email)), 
   NOT(ISBLANK(Email)), 
   OR(ISBLANK(Email_Source__c), ISBLANK(Email_Date__c), ISBLANK(Email_Person__c))
)

 

All Answers

Chris  ByromChris Byrom
It looks like you just need to move around your parenthesis. If you format these like code, you can see what the problem is.
 
​AND(
    OR(
        ISNEW(),
        ISCHANGED(Email)),
        ISBLANK(TEXT(Email_Source__c))
    )
)

You are telling it to throw the error if it is new, the email has been changed, or your field is blank. The and is doing nothing. I am assuming one of these items need to be moved to the AND possibly like this.
 
AND(
    OR(
        ISNEW(),
        ISCHANGED(Email))        
    ),
    ISBLANK(TEXT(Email_Source__c))
)

 
RaidanRaidan
Hi Kelly,

I think the formula will look like below (I also included the ISCLONE(), in case the record is cloned). You probably also need to change the field names below since I don't know their real API names.

AND(
   OR(ISNEW(), ISCLONE(), ISCHANGED(Email)), 
   NOT(ISBLANK(Email)), 
   OR(ISBLANK(Email_Source__c), ISBLANK(Email_Date__c), ISBLANK(Email_Person__c))
)

 
This was selected as the best answer
Kelly TetlockKelly Tetlock
Thanks Chris and Raldan for such a speedy reply!!  I tried Chris' solution first and was getting various syntax errors, so I thought I would try Raldan's instead and entered the appropriate API names and it worked like a charm!  Thanks to you both though!
lakshmi yelurilakshmi yeluri
When  user  click to  change record type previous record field value was saved default ,so we throw the  error if default values  and fields is not  equal to blank using validation rule