+ Start a Discussion
Ricardo OrtegaRicardo Ortega 

Junction Objects

Hello, I wanted to know if you could tell me how can I validate that a person cant create a junction object twice using the same relationships. For example, I have a junction object between contacts and programs and i dont want people create the same junction object using a contact that is already with one program. I created a trigger to help me before insert and update but I havent been able to test it (**bleep** tests -_-) so I want to know if there is a way to make the information unique without using the trigger. Thanks

Best Answer chosen by Admin (Salesforce Developers) 
JayNicJayNic

Without triggers, you could use a wf rule to update a field that is marked as 'do not allow duplicates'

 

So create field called: 'DuplicateKey__c' as text(37). Make sure to check the 'do not allow duplicate values' option

 

The create a workflow rule that runs all the time (formula = 'true') and a field update that updates the field like so:

CASESAFEID(LookupField1__c) & '-' & CASESAFEID(LookupField2__c)

 

 

Once you update all records in the system, you can attempt to insert a dupe - it will give you the error

All Answers

JayNicJayNic

Without triggers, you could use a wf rule to update a field that is marked as 'do not allow duplicates'

 

So create field called: 'DuplicateKey__c' as text(37). Make sure to check the 'do not allow duplicate values' option

 

The create a workflow rule that runs all the time (formula = 'true') and a field update that updates the field like so:

CASESAFEID(LookupField1__c) & '-' & CASESAFEID(LookupField2__c)

 

 

Once you update all records in the system, you can attempt to insert a dupe - it will give you the error

This was selected as the best answer
Ricardo OrtegaRicardo Ortega

Thank you JayNic I will try this right now.