Hi Priti,You can use the below code: <------ Apex class--->>>>>
<<<---- Trigger------>>>>public class UpdateFields {
public static void updateCustom1fields(List<Custom2__c> listOfCustom2){
try{
if(listOfCustom2 != NULL){
System.debug('subhasis');
List<Custom1__c> existingList = new List<Custom1__c>();
existingList = [SELECT Id, Id__c, CTC__c FROM Custom1__c LIMIT 50000];
Map<Id, List<Custom1__c>> idVsCustom1 = new Map<Id, List<Custom1__c>>();
if(existingList.size() > 0){
System.debug('subhasis');
for(Custom1__c object1 : existingList){
for(Custom2__c object2 : listOfCustom2){
if(object1.Id__c == object2.Id__c){
object1.CTC__c = object2.Bonous__c + object2.Expense__c;
}
}
}
Update existingList;
}
}
}catch(Exception exp){
System.debug('Exception Cause'+exp.getCause()+'Line Number'+exp.getLineNumber());
}
}
}
I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.Thanks,Ajay Dubeditrigger UpdateFields on Custom2__c (after Update, after insert) {
if(Trigger.isAfter )
if(Trigger.isInsert || Trigger.isUpdate){
UpdateFields.updateCustom1fields(Trigger.new);
}
}
6 answers