In various business scenarios, we find need of creating a many-to-many
relationship in salesforce between two objects to allow each record of one
object to be linked with multiple records from another object and vice versa.
To do so we create a junction object with two master-detail
relationships, and we log the junction record entries in salesforce to link
records from both the master objects.
Imagine a scenario,
we log multiple junction record entries having the same set of master records!
Considering an example with A1 an Account record and C1 a Customer record. We can create multiple customer account (CA) records having
same A1 and C1 referencing.
Below are some basic salesforce
administrative steps to restrict the duplicate entries:
- Create a custom filed (i.e. “UID”) on junction object with "Text" data type and “Unique” and “Case Sensitive” option checked.
- Set the filed level security for “UID” and make it read only for all the profiles.
- Create a workflow rule for field update on junction object.
- Update the “UID” filed value through the workflow, by appending the “Account ID” and “Customer ID” value.
- And that's all!
Now whenever any user
tries to log a duplicate entry, salesforce will restrict it by showing an
error message referring to "UID" filed.