Print this page

How to update fields on an object when a user clicks the reject/approve button on an approval process?

Knowledge Article Number 000181672
Description How to write a trigger that updates data on an object that is called every time a user clicks the Approve/Reject button in approval process?
We can achieve this requirement in 2 ways:

Scenario 1:
  1. Create new custom field (checkbox) in the object( make sure this is not in any page layout so that no one accidentally checks or unchecks this field).
  2. Create a Field Update for the Checkbox created in step 1. Field Update sets Checkbox to TRUE if there is an approval or rejection action in the approval process. 
  3. This field update would fire an update trigger on an object. 
  4. In your trigger check  if this field is updated, If yes, then perform update logic

trigger approve/reject trigger on opportunity( after update)
	for (opportunity opp :
 		if(opp.customfield__c == true)
			//perform update logic

Scenario 2:

>> Completely override the approval process by forcing users through a custom button flow

promote demote