You need to sign in to do that
Don't have an account?
Junction Object Validation Rule guidance
Hi
I have a junction object called CaseIssue whith two master detail relationships. On one side is Case (Case_Number__c_) , on the other side is Issue (Issue_id__c). This setup allows us to establish a many to many relationship between cases and issues. Pretty standard stuff.
I would like to ensure however, that we are not linking the same Issue record to a single case record more than once (and vice versa not linking the same Case record to a single Issue record more than once).
The first thing that ocurred to me was VLOOKUP, but I am unsure if this is right? Any help would be greatly appreciated.
You'll need to do this in Apex as follows:
1. Create an Apex Trigger on before insert of your junction object
2. In your trigger, iterate through the records inserted and for SELECT back the id's you're checking
3. If you find a match for the Case and Issue Id it won't be the current record (as it hasn't been written yet in a before insert trigger), all you need to then do is call the .addError method on the record
Depending on your objects it should look something like this:
All Answers
Hi Stevemo,
Thanks for the suggestion. I am unclear how to use this to my advantage however. It is easy enough to create a rollup summary on the Case object to count the total number of CaseIssues attached, however how can I use a raw count like that to determine uniqueness?
I have a junction object CaseIssue with 3 fields, Name, Case_ID and Issue ID.
I need to be sure that when I save a CaseIssue Record with Case_ID XYZ and Issue ID ABC that for every other CaseIssue Record with Case_ID XYZ, the Issue ID Value is not ABC. If it is, I need an error.
Sorry if I seem a little unclear or slow on the uptake, I'm a Salesforce rookie.
Thanks again.
Hmmmmm... you're right, this is gonna be a tougher nut to crack than I thought.
Lemme take another look at it
You'll need to do this in Apex as follows:
1. Create an Apex Trigger on before insert of your junction object
2. In your trigger, iterate through the records inserted and for SELECT back the id's you're checking
3. If you find a match for the Case and Issue Id it won't be the current record (as it hasn't been written yet in a before insert trigger), all you need to then do is call the .addError method on the record
Depending on your objects it should look something like this:
Thanks a million Enth, this is exactly what I need. I appreciate the help and am busy dissecting the example to learn something from it.