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
anshuman mishraanshuman mishra 

Validation rule for Junction Object to check if both parents have been repeated or not


0down votefavorite

I am creating a junction object called Candidate_Position.This has two parents candidate and position.I have to go to the Candidate Detail page and in the related list create a new Candidate Position.The next page is a VF page where I select the Position to associate with the new Candidate Position and click save.The condition however is,I have to validate if the position I am associating is not already associated with any Candidate Position having the same Candidate parent. For example if there is Candidate "Paul",and under that I am creating a Candidate Position trying to associate Position "Dev",the other Candidate Positions under Candidate "Paul" should not have "Dev" as parent Position.

So what Validation Rule I have to give for the Junction Object?

I am completely new to Salesforce,and would appreciate some answers.Thanks :-)
sachin kadian 5sachin kadian 5
You can achieve this using 1 text field and 1 workflow on candidate_position.

1) Create 1 text field on candidate_position and make it unique(checking unique checkbox true)
2) create a workflow on candidate_position for "every time created and updated" . It will update the newly checkbox with position.Name+candidate+name. 

and Its done.

first you will create candidate with Paul , dev and it will create candidate_position record and workflow will update the text field with paul+dev.
2nd time if you will try to create the record with same vaules, it will through the error as it is unique field.
Shikha AgashiShikha Agashi
You can only do this using Before Insert/Update event on Trigger on Candidate Position. You need to use this logic in combination of unique text field on Candidate POsition object.