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

How to Recall an Account's Prior Address Information when an Approval is Rejected

Hello, I'm fairly new to triggers, but I've set up a very simple trigger to kick off an approval process whenever an account's address information is changed.

trigger Updated_Customer_Approval_Process on Account (after update) 
    for(Account a:{ 

    if (
         trigger.oldmap.get( <> a.Name || 
	 trigger.oldmap.get( <> a.ShippingStreet ||
         trigger.oldmap.get( <> a.ShippingCity || 
         trigger.oldmap.get( <> a.ShippingState ||
         trigger.oldmap.get( <> a.ShippingPostalCode ||
	 trigger.oldmap.get( <> a.ShippingCountry
    Approval.ProcessSubmitRequest req1 = new Approval.ProcessSubmitRequest();
    req1.setComments('The following customer, ' + a.Name + ', has been updated and requires your approval.');
    Approval.ProcessResult result = Approval.process(req1);}

If the Account is rejected, I have set up several Rejection Field Updates so that the fields would return to the previous data values:






However, none of these field updates work. Instead of returning the prior value, they return the current value that the user just entered.



Since this didn't work, I also tried using a workflow rule. Basically, I created a workflow rule that ran every time a record is created or edited, and stored the prior value of the address fields into additional custom fields I had created. However, this workflow seems to conflict with the approval process I created, because I get the following error.


There were custom validation error(s) encountered while saving the affected record(s). The first validation error encountered was "Apex trigger Updated_Customer_Approval_Process caused an unexpected exception, contact your administrator: Updated_Customer_Approval_Process: execution of AfterUpdate caused by: System.DmlException: Process failed. First exception on row 0; first error: ALREADY_IN_PROCESS, Cannot submit object already in process.: []: Trigger.Updated_Customer_Approval_Process: line 19, column 1".


My question is, Do I need to use Apex to recall the previous address information if the account is rejected through the Approval Process? If so, would this require a new Trigger to be kicked off after the request is rejected, and if so, how would I go about doing that.