function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Andrew ByrnsAndrew Byrns 

Apex Trigger for Approval History

User-added image

I'd like to write a trigger that will modify the opportunity when an approval is approved. The snapshot shows an approval for discounts. When the discount is too high for a particular opportunity it is flagged for approval. Once the approver approves the opportunity I'd like a few fields to be autofilled. What object do I need to attach this trigger to, if this is indded possible? I would assume that some object exists for the approval. 

​In the Eclipse Force.com IDE I don't see any object for approval when writing new triggers. Your thoughts/assistance are much appreciated!
 
hitesh90hitesh90
Hello Andrew,

There is no need to write apex trigger for your requirement. it can be achieve by field update on approval process. follow below steps.
1. Go to your Approval Process.
2. Scroll down to "Final Approval Actions" section.
3. Click on "Add New" --> "Field Update".
4. Select the field which you want to Update and click on "Save".

Let me know if you have any question on this. Please mark this "Solved" if it helps.

Thank You,
Hitesh Patel
Email :- hiteshpatel.aspl@gmail.com
http://mrjavascript.blogspot.in/
Ajay mishraAjay mishra
Hi Andrew,

You can use ProcessInstance Object to check your record is approved or not.

Also can use below query in your opportunity Trigger:  

cessInstance[] pi = [Select ID, Status, TargetObject.Name From ProcessInstance Where TargetObjectID = 'YOURRECID'];

On this basis you can do updation in the reocrd.

Thanks,
Ajay Mishra
Email: mishraajay.m1@gmail.com