You need to sign in to do that
Don't have an account?

Trigger to update Checkbox on parent record not working
Hi,
I'm trying to check a checkbox on the parent opportunity when a child record is created.
When I test the trigger below, the debug log says the checkbox has been updated to true. However when I check the opportunity is has not. I'm quite new to developing in general so apologies if this is something obvious:
trigger updateOppCb on Bonus_Calculator__c (before insert) {
// Create a set of related opps
set <id> ids = new set <id>();
for (Bonus_Calculator__c newSet : Trigger.new)
ids.add(newSet.opportunity__c);
// Add child? checkbox to map
map <id,Opportunity> childMap = new map<id,Opportunity>();
for (Opportunity o:[select child__c from opportunity where id in :ids])
childMap.put(o.id, o);
for (Bonus_Calculator__c newBonus : Trigger.new) {
Opportunity o = childMap.get(newBonus.opportunity__c);
o.child__c = true;
system.debug('opportunity = '+ o);
}
}
...Thanks a million for any help!
Try below code :-
If this helps,please mark it as best answer to help others :)
All Answers
Try below code :-
If this helps,please mark it as best answer to help others :)
When I tried this i get a 'you have tried to dereference a null pointer...' exception. Do you happen to know why this might be?
Thanks again