I have 2 objects Opportunity(Parent) and Bigmachines (child), i have check box field (flagPhyscianProctor__c) on both the objects so when this check box is checked on any of it's child records then the parent field (flagPhyscianProctor__c) has to be checked and viceversa, here is my trigger, it works in some scenarios but in one of my scenario where i have Opp and it has 4 quotes where i enabled checkbox on 2 of the quotes,when i edit and save the opp the check box got updated to true but when i unchecked it on one of the quote where on the other quote it is still set to true the check box on opp gets deactivated, somehow it's not validating all the child records, not sure what was the issue
trigger PhyscianProctor on BigMachines__Quote__c (after insert, after update) {
list<Opportunity> listofParentObjToUpdate;
set<Id> setOfids = new set<Id>();
Map<Id,BigMachines__Quote__c> mapIdVsBigMachines = new Map<Id,BigMachines__Quote__c();
for(Integer i=0;i<Trigger.new.size();i++){
if(Trigger.new[i].flagPhyscianProctor__c==true || Trigger.new[i].flagPhyscianProctor__c==false){
mapIdVsBigMachines.put(Trigger.new[i].BigMachines__Opportunity__c,Trigger.new[i]);
}
}
if(!mapIdVsBigMachines.isEmpty()){
list<Opportunity> listOfParentObj = [select id,flagPhyscianProctor__c from Opportunity where Id IN: mapIdVsBigMachines.keySet()];
listofParentObjToUpdate = new list<Opportunity>();
for(Opportunity parent : listOfParentObj) {
parent.flagPhyscianProctor__c = mapIdVsBigMachines.get(parent.id).flagPhyscianProctor__c;
listofParentObjToUpdate.add(parent);
}
Update listofParentObjToUpdate;
}
}