You need to sign in to do that
Don't have an account?
Jacek D
How to run Apex trigger after successful approval workflow?
I'd like to run an Apex trigger that updates the owner field on the contract page once the contract is successfully approved. I know how to update the owner field, but I don't know how to make the trigger run at the given time.
Any suggestions on how to do that?
Thanks!
I hope your approval process changes the approval status field, if not try it[ create a picklist Approval Status with values 'Pending', 'Approved', 'Rejected']. Once the record is submitted set the status to Pending, via approval process's workflow.
When approved change status to Approved. In the trigger(after update) check the Approval status, if it is approved, then change the owner.
Hope it helps.
All Answers
If you have a before/after update trigger on your object, then when the approval is successful you can carry out a workflow field update which will cause the trigger to fire.
Ah, so I use field update to change the status of a field (e.g. status__c) and then have the trigger run a logic like this:
If status__c = approved
then lookupfield = WhateverTheSource
???
Thanks for helping me out on this, I am a newbie in Apex.
I hope your approval process changes the approval status field, if not try it[ create a picklist Approval Status with values 'Pending', 'Approved', 'Rejected']. Once the record is submitted set the status to Pending, via approval process's workflow.
When approved change status to Approved. In the trigger(after update) check the Approval status, if it is approved, then change the owner.
Hope it helps.
One additional point - you'd usually check that the value of the field has changed rather than just checking its value, if it was left as true from a previous transaction.
E.g. if you have a custom field called "RunApprovalTrigger__c:
Yes, that will work. I won't even have to reset the field causing the trigger to run!
Thanks a bunch!
Minor edit to Bob's code sample that confused me at first.
was:
trigger.old.get(myObj.id).RunApprovalTrigger__c
should be:
trigger.old.getMap(myObj.id).RunApprovalTrigger__c
Thanks for the code sample!
--Brian