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
Ravi_SFDCRavi_SFDC 

Validation Rule for Objects

I have 2 objects Contact (Standard Object) and Task (Custom Object). Contact has a lookup from Program Object.

1. I would assign a program to a contact as lookup

2. When a contact is trying a create a task, he/she should be able to create a task under the program he/she belongs to (as the program is assigned to a contact object).

3. if the contact is trying to create a task with respect to any other program it should through the contact an error as he don't have a prvilege to create a task for that program.

Your help would be really appreciated.

Regards
Ravi

 

SubratSubrat (Salesforce Developers) 
Hello Ravi ,

To achieve the desired functionality, you can follow these steps:

Create a Lookup Field:
In the Contact object, create a lookup field named "Program" that references the Program object.

Reference video -> https://www.youtube.com/watch?v=7_eWSqcNc1k

Task Creation Validation:
Implement a validation rule on the Task object to enforce that the Contact can only create a Task related to their assigned Program.
Go to the Task object's setup and navigate to the Validation Rules section.
Create a new validation rule with a suitable name and description.
Use the formula editor to define the validation rule based on the following criteria:
ISPICKVAL(Program__r.Id, Contact_r.Program_c)
Error Message:
Specify an appropriate error message to display when the validation rule condition is not met.
Save the validation rule.
Now, whenever a Contact creates a Task, the validation rule will check if the Task's Program matches the Contact's assigned Program. If they do not match, an error message will be displayed, indicating that the Contact does not have the privilege to create a Task for that Program.

Hope this helps !
Thank you.