Im confused becauyse this trigger code is working in the sandbox and was working in production yesterday but today im getting
Error:Apex trigger sendDAP1Invites caused an unexpected exception, contact your administrator: sendDAP1Invites: execution of BeforeUpdate caused by: System.DmlException: Upsert failed. First exception on row 0 with id a04U0000009HitMIAS; first error: SELF_REFERENCE_FROM_TRIGGER, Object (id = a05U0000004JwIT) is currently in trigger sendDAP1Invites, therefore it cannot recursively update itself: []: Trigger.sendDAP1Invites: line 18, column 1
The trigger code is very simple all its doing is checking a checkbox on a child object when a parent object is updated?
trigger sendDAP1Invites on DAP_Session__c (before update) {
List<DAP_Session_Assignment__c> rows = new List<DAP_Session_Assignment__c>();
for (DAP_Session__c session : Trigger.new) {
if (session.Invite_Status__c == 'live') {
// check old session status
DAP_Session__c oldSession = Trigger.oldMap.get(session.ID);
if (session.Invite_Status__c != oldSession.Invite_Status__c) {
for (DAP_Session_Assignment__c score : [Select Id, Invited__c from DAP_Session_Assignment__c where DAP_Session__c = :session.id ]) {
//update all the scores to invited!
score.Invited__c = true;
rows.add(score);
}
}
}
}
upsert rows;
}