You need to sign in to do that
Don't have an account?
Neelima Kongathi
Is there any way to get this soql and dml out of the loop in this code??
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 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);
}
Please try the following code Do reply if there is any issue with the code. To my best guess this should work, but if any thing creates a problem do let me know will help you futher with the solution. If you get any problem occoured solved yourself, then also comment with the correct solution here.
Also if my reply helped you kindly mark my answer as Best.
Regards,
Somya Tiwari
Please try this code:
I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.
Thanks and Regards,
Deepali Kulshrestha
www.kdeepali.com