You need to sign in to do that
Don't have an account?
Rui Wang 7
apex trigger not fired after workflow field update
HI, Salesforce experts:
We have following requirement. Salesforce sends out email, recipient replies to the email then salesforce updates the associated case status via workflow field update, at last case assignment rule should be triggered via apex trigger upon the case status update. All work well except the apex trigger is not fired, which breaks whole process and case assignment rule is not invoked at all. But based on the salesforce document, the workflow field update can fire the after trigger. Any idea?
Thank you!
Roy
We have following requirement. Salesforce sends out email, recipient replies to the email then salesforce updates the associated case status via workflow field update, at last case assignment rule should be triggered via apex trigger upon the case status update. All work well except the apex trigger is not fired, which breaks whole process and case assignment rule is not invoked at all. But based on the salesforce document, the workflow field update can fire the after trigger. Any idea?
Thank you!
Roy
Excerpt of Salesforce Order of Execution:
- Loads the original record from the database or initializes the record for an upsert statement.
- Loads the new record field values from the request and overwrites the old values. Salesforce runs some system validation rules depending on if request came from UI Edit page
- Executes all before triggers.
- Runs most system validation steps again, such as verifying that all required fields have a non-null value, and runs any user-defined validation rules.
- Executes duplicate rules. If the duplicate rule identifies the record as a duplicate and uses the block action, the record is not saved and no further steps, such as after triggers and workflow rules, are taken.
- Saves the record to the database, but doesn’t commit yet.
- Executes all after triggers.
- Executes assignment rules.
- Executes auto-response rules.
- Executes workflow rules.
- If there are workflow field updates, updates the record again.
- If the record was updated with workflow field updates, fires before update triggers and after update triggers one more time (and only one more time), in addition to standard validations. Custom validation rules and duplicate rules are not run again.
before update and after update triggers will fire, then the workflow fires.Hope this helps you!
If my answer helps resolve your question , please mark it as the 'Best Answer' & upvote it to benefit others.
Thanks
checked on the execution order, on rule 12, it says the apex trigger will fire one more time after workflow rule field update, any thought?
Use context variable such as Trigger.isInvokedByFieldUpdate
trigger xxxxx on Case (after update) {
List<Case> caseList = new List<Case>();
if(Trigger.isAfter && Trigger.isUpdate){
for (Case caseObj : Trigger.new) {
system.debug('start trigger iteraion');
if(caseObj.IsEscalated == true && caseObj.IsEscalated != Trigger.oldMap.get(caseObj.id).IsEscalated){
xxxxxxx
}
else if(caseObj.Status == 'Response Received' && caseObj.Categ__c == 'Account Administration' && Trigger.oldMap.get(caseObj.id).Status !='Response Received'){
system.debug('Entity Tranfer Response Received: ' + caseObj.Id);
caseList.add(new Case(id = caseObj.id));
}
}
if(caseList.size() != 0){
Database.DMLOptions dmo = new Database.DMLOptions();
dmo.assignmentRuleHeader.useDefaultRule = true;
Database.update(caseList, dmo);
system.debug('Assigment Finished');
}
}
}