• Neelima Kongathi
  • NEWBIE
  • 5 Points
  • Member since 2018

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 1
    Replies
List<Consultant__c> toBeSubmittedCons = [select id,Pan_Number__c,category__c,Phone__c,Email__c,System_otp__c,owner.IT_HEAD__c,owner.NON_IT_HEAD__c from Consultant__c];

custom object : Consultant__c
custom fields in user object
1.IT_HEAD__c : lookup to user
2.NON_IT_HEAD__c :lookup to user
public class DuplicatePanCheck {
    public static void duplicatePanNo(List<Consultant__c> cons){
        for(Consultant__c c: cons){
                if(c.Pan_Number__c!= null){ 
                List<Consultant__c> con = [select id,Pan_Number__c,Phone__c,Email__c from Consultant__c where Pan_Number__c =: c.Pan_Number__c];  //checking the duplicate record based on the pan number
                        if(con.size()>1){
                        for(Consultant__c cn : con){   //if duplicate records found, updating phone, email fields in the old records 
                            cn.Phone__c = c.Phone__c;
                            cn.Email__c = c.Email__c;
                        }
                    update con;
                }
            }
        }
    }
}

trigger Trigg_DuplicatePanCheck on Consultant__c (after insert) {
    DuplicatePanCheck.duplicatePanNo(Trigger.new);
}
 
public class DuplicatePanCheck {
    public static void duplicatePanNo(List<Consultant__c> cons){
        for(Consultant__c c: cons){
                if(c.Pan_Number__c!= null){ 
                List<Consultant__c> con = [select id,Pan_Number__c,Phone__c,Email__c from Consultant__c where Pan_Number__c =: c.Pan_Number__c];  //checking the duplicate record based on the pan number
                        if(con.size()>1){
                        for(Consultant__c cn : con){   //if duplicate records found, updating phone, email fields in the old records 
                            cn.Phone__c = c.Phone__c;
                            cn.Email__c = c.Email__c;
                        }
                    update con;
                }
            }
        }
    }
}

trigger Trigg_DuplicatePanCheck on Consultant__c (after insert) {
    DuplicatePanCheck.duplicatePanNo(Trigger.new);
}