You need to sign in to do that
Don't have an account?
Jas Salesforce
Duplication rule on Junction Object
Hi Team, (this is my original question where Charu helped me but the code is not working, so adding more details for help please)
I got a junction object on Account for Account-Account relationship with one master-details field ( Account_to_c) and lookup field (Account_from) which is linking accounts to multiple accounts.
i need to add duplication rule to avoid mulitple entries in 'Account to' and 'account from' field. Rule should check if Acount A's relationship exist in either Account to or Account from lookups then show a error when creating duplicate entry.
Standard duplicate rules and workflow rule options are not working.
Thanks so much for the help, but it is firing up. code is as below, has no errors. Accounts relationship is a custom object has two fields Accounts to and account from added on accounts as related list so can add multiple account relationships. User can add new relationship from 'Account to' relationship related list and that will show up on reciprocal account in 'Account from' related list. Would like system should check duplicates in Account to and Account From related list when adding new relationship from 'Account to'
---------------------------------------------------------------------------------------------------------------------------------------------------------
trigger PreventDuplicationonAccountrelationship on Account_Relationship__c (before insert,before Update) {
Set <Id> AccFromId = new Set<Id>();
Set <Id> AccToId = new Set<Id>();
if(trigger.IsBefore &&(Trigger.IsInsert || Trigger.IsUpdate)){
for (Account_Relationship__c Acc:trigger.new) {
AccToId.add(Acc.Account_To__c);
AcctoId.add(Acc.Account_From__c);
}
}
List <Account_Relationship__c> lstAcc = [SELECT Account_To__c,Account_From__c FROM Account_Relationship__c WHERE Account_To__c IN :AccToId AND Account_From__c in :AccFromId ];
for (Account_Relationship__c Acc2:trigger.new) {
If (lstAcc.size() > 0) {
Acc2.Account_To__c.adderror( 'Duplicate Account Found' );
Acc2.Account_From__c.adderror( 'Duplicate Account Found' );
}
}
}
----------------------------------------------------------------------------------------------------------------------------------
Object view, as you can see that i can add multiple accounts from 'Relationship to' related list and see same account added from 'Relationship from' list too.
I got a junction object on Account for Account-Account relationship with one master-details field ( Account_to_c) and lookup field (Account_from) which is linking accounts to multiple accounts.
i need to add duplication rule to avoid mulitple entries in 'Account to' and 'account from' field. Rule should check if Acount A's relationship exist in either Account to or Account from lookups then show a error when creating duplicate entry.
Standard duplicate rules and workflow rule options are not working.
Thanks so much for the help, but it is firing up. code is as below, has no errors. Accounts relationship is a custom object has two fields Accounts to and account from added on accounts as related list so can add multiple account relationships. User can add new relationship from 'Account to' relationship related list and that will show up on reciprocal account in 'Account from' related list. Would like system should check duplicates in Account to and Account From related list when adding new relationship from 'Account to'
---------------------------------------------------------------------------------------------------------------------------------------------------------
trigger PreventDuplicationonAccountrelationship on Account_Relationship__c (before insert,before Update) {
Set <Id> AccFromId = new Set<Id>();
Set <Id> AccToId = new Set<Id>();
if(trigger.IsBefore &&(Trigger.IsInsert || Trigger.IsUpdate)){
for (Account_Relationship__c Acc:trigger.new) {
AccToId.add(Acc.Account_To__c);
AcctoId.add(Acc.Account_From__c);
}
}
List <Account_Relationship__c> lstAcc = [SELECT Account_To__c,Account_From__c FROM Account_Relationship__c WHERE Account_To__c IN :AccToId AND Account_From__c in :AccFromId ];
for (Account_Relationship__c Acc2:trigger.new) {
If (lstAcc.size() > 0) {
Acc2.Account_To__c.adderror( 'Duplicate Account Found' );
Acc2.Account_From__c.adderror( 'Duplicate Account Found' );
}
}
}
----------------------------------------------------------------------------------------------------------------------------------
Object view, as you can see that i can add multiple accounts from 'Relationship to' related list and see same account added from 'Relationship from' list too.
>> https://salesforce.stackexchange.com/questions/12755/how-to-apply-uniqueness-on-junction-object
I was checking the possibilities and one was mentioned in the above link can you try checking the mentioned way once?
I am adding the best answer mentioned in the above link for quick reference:
Let me know if it helps you and close your query by marking it as the best answer so that it can help others in the future.
Thanks.