I have Custom Field in Standard Object called Accounts
Then i create custom Field called Priority (API Key_Priority__c
) which is a PickList(1,2,3,4,5)
Then I created Custom Object Customer (Structure is below). here Title, First_Name, Last_Name combination is unique.
What i need to do is
At any given time, there should be only unique records in the system
If a duplicate record found, latest record should be in the system while the previous should get deleted
- If the latest Customer record has a “Ref. Account” with lesser prioriy than the duplicate found record; change the “Ref. Account” of the latest Customer record to the higher priority account if found on the duplicate record. The latest customer record should have the highest priority account with respective to its duplicate. (Note: Priority 1 is the min, Priority 5 is the max)
I wrote Apex class as per my knowledge and I cant go beyond that point, Please help me with this issue.
public class checkDuplicateCustomer{
public static void applyDiscount(Cutomer__c[] cutomers, Customer__c newCutomer) {
List<Customer__c> newCustomer = new List<Customer__c>();
for (Customer__c existingCustomer :cutomers){
if((newCutomer.Title__c == existingCustomer.Title__c)&&(newCutomer.First_Name__c == existingCustomer.First_Name__c)&&(newCutomer.Last_Name__c == existingCustomer.Last_Name__c)){
if(newCustomer.Account__c.Priority__c > existingCustomer.Account__c.Priority__c){
}
}
}
}
}