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
Amit VaidyaAmit Vaidya 

Validation rule to validate if user with profile updates/creates contact

How to validate using validation rule that if a user with profile: Sales User or Sales User - SpringCM updates/creates a contact, and email != null: require that at least one of the checkboxes is checked for fields:

HasOptedOutOfEmail 
Stream_Opt_In__c 
Invite_Opt_In__c 
Newsletter_Opt_In__c

Please help me in this.
Best Answer chosen by Amit Vaidya
Ashish_SFDCAshish_SFDC
Hi Amit, 


- $Profile.Id  will give the Current user's profile, 

You can have a logic like 

If (

AND (profile id = sales user profile id ,

Email = null ,

HasOptedOutOfEmail = false ,

Stream_Opt_In__c = false ,

Invite_Opt_In__c = false ,

Newsletter_Opt_In__c = false )

)

If this meets the criteria then it will throw the Validation error else will save the record. 


Regards,
Ashish

All Answers

Ashish_SFDCAshish_SFDC
Hi Amit, 


- $Profile.Id  will give the Current user's profile, 

You can have a logic like 

If (

AND (profile id = sales user profile id ,

Email = null ,

HasOptedOutOfEmail = false ,

Stream_Opt_In__c = false ,

Invite_Opt_In__c = false ,

Newsletter_Opt_In__c = false )

)

If this meets the criteria then it will throw the Validation error else will save the record. 


Regards,
Ashish
This was selected as the best answer
Amit VaidyaAmit Vaidya
Hi Ashish,

Thank you for helping on this.

I have just modified it by removing 'if' according to my requirement. Please let me know if it correct:

AND (
OR
(
$Profile.Id = "sales user profile id",
$Profile.Id = "sales user profile id"
),
Email != null,
HasOptedOutOfEmail = false,
Stream_Opt_In__c = false,
Invite_Opt_In__c = false,
Newsletter_Opt_In__c = false
)

I have created this validation rule on both Contact and Lead object.

Please let me know if I am going wrong anywhere.

Thank you,
Amit
Ashish_SFDCAshish_SFDC
Hi Amit, 


I had given the blue print - your's seem correct to your business logic. 

Try that out and see, in your Dev / Sandbox org input few dummy records and see if that throws the Validation error as expected. 

Reply back if you have any further questions. 


Regards,
Ashish