I have a trigger which will update checkbox on a child object when Update is made on Parent for mLookup__c field. But the checkbox is always false even after the trigger is executed.
Can anyone please help me with this ?
Trigger:
trigger updatefield on customObj__c (before update)
{
Set<ID> Ids = new Set<ID>();
for(customObj__c cb : trigger.new){
Ids.add(cb.ID);
}
List<customObj__c> cbList = [Select ID,Name,mLookup__c from customObj__c where ID IN:Ids];
List<Product__C> prodlist = [Select Id,checkbox__c,relatedCB__Lookup__c from Product__C where relatedCB__Lookup__r.Id IN: Ids];
List<Product__C> updateList = new List<Product__C>();
for(customObj__c op: cbList){
if(!prodlist.isEmpty()){
for(Product__C prod :prodlist){
if(op.mLookup__c != null){
prod.checkbox__c = true;
}
// when checked in debug it is always entering this condition
if(op.mLookup__c == null){
prod.checkbox__c = false;
}
updateList.add(prod);
}
}
}
Update updateList;
}