if Custom_Object2__c update then checkbox field will update on Custom_Object1__c description field. trigger updateaccountfield on Custom_Object2__c (after insert, after update,after delete) {
List<ID> AccID = New List<ID>();
for(Custom_Object2__c con : Trigger.new){
if(con.Custom_Object1__cId!=null&& con.Custom_Object1__cId != null){
AccID.add(con.Custom_Object1__cId);
}
}
List<Custom_Object2__c> ctwoList = [ select Id, checkbox___C from Custom_Object2__c where accountId in :AccID];
List<Custom_Object1__c> coneList = [SELECT Id, description FROM Custom_Object1__c WHERE id in :AccID];
String checkbox;
for(integer j = 0 ; j < ctwoList.size(); j++){
if(j==0){
checkbox = ''+ctwoList[j].get('checkbox___C');
system.debug('checkbox__c@@@1'+checkbox__c);
}else{
checkbox = checkbox__c+''+ctwoList[j].get('checkbox___C');
system.debug('checkbox__c@@@1'+checkbox__c);
}
}
Custom_Object1__c cone = new Custom_Object1__c();
cone.Id= coneList[0].Id;
cone.Description=checkbox;
update cone;
}
2 answers