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
sfdc_beginner7sfdc_beginner7 

Duplicate check in case of 2 look up fields

There is a custom object Designation which have 3 fields :
Employee_Designation (text) ,
Account_Name(look up to account),
Contact_Name(look up to contact)
I want to do  a duplicate check so that value in all the 3 field should be different.
Eg : Suppose there is an existing record in Designation
  Employee_Designation=Test Lead and Account_Name=Universal containers and Conatct_Name=Daniel Philz
i dont want any new or updated record to have same values in all 3 fields
If i go for duplicate management rule ,then the matching rule wont allow 2 look up fields.
How it can be done?
 
Shawn Reichner 29Shawn Reichner 29
I would write a trigger on the Designation Object (Before Insert) and take the records coming in via the Trigger.new and add them to a list, then do a SOQL query to query the Designation object to find any records where Employee_Designation__c EQUALS the trigger.new variable.Employee_Designation__c and Account_Name__c Equals trigger.new variable.Account_Name__c and the same for the last field.  Then I woudl do a For loop to go through those records found by the list and if any found then throw an error to the user that a duplicate has been found and do not allow save of the record.   Does this make sense?