I'm trying to build a trigger that will take the value of a Child Object on the Opportunity and write that value to a field on the Opportunity Level.
There are no errors and it seems to run successfully but when I check the Opportunity afterwards the field "Status__c" was not updated.
This is my first attempt at writing a trigger and any help would be greatly appreciated!
trigger updateStatusOnAccountAndOpp on Customer_Success__c (after update, after insert) {
// Find all the customer success records that have a standing assigned.
List<Customer_Success__c> accountsAndOppsToUpdate = [SELECT Id, Standing__c, Opportunity__r.Status__c
FROM Customer_Success__c
WHERE Standing__c = 'Good' OR Standing__c = 'Acceptable' OR Standing__c = 'Poor'];
for (Customer_Success__c currentCSRecord : accountsAndOppsToUpdate) {
if(recursiveTriggerPrevent.runonce()){
if (currentCSRecord.Standing__c == 'Good') {
currentCSRecord.Opportunity__r.Status__c = '/img/samples/flag_green.gif';
update currentCSRecord;
} else if (currentCSRecord.Standing__c == 'Acceptable') {
currentCSRecord.Opportunity__r.Status__c = '/img/samples/flag_yellow.gif';
update currentCSRecord;
} else {
currentCSRecord.Opportunity__r.Status__c = '/img/samples/flag_red.gif';
update currentCSRecord;
}
}
}
}