+ Start a Discussion
MikeyJamJamsMikeyJamJams 

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: trigger.new){ 

    if (
         trigger.oldmap.get(a.id).Name <> a.Name || 
	 trigger.oldmap.get(a.id).ShippingStreet <> a.ShippingStreet ||
         trigger.oldmap.get(a.id).ShippingCity <> a.ShippingCity || 
         trigger.oldmap.get(a.id).ShippingState <> a.ShippingState ||
         trigger.oldmap.get(a.id).ShippingPostalcode <> a.ShippingPostalCode ||
	 trigger.oldmap.get(a.id).ShippingCountry <> a.ShippingCountry
        )
    {
    Approval.ProcessSubmitRequest req1 = new Approval.ProcessSubmitRequest();
    req1.setComments('The following customer, ' + a.Name + ', has been updated and requires your approval.');
    req1.setObjectId(a.id);
    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:

PRIORVALUE(Name)

PRIORVALUE(ShippingStreet)

PRIORVALUE(ShippingCity)

PRIORVALUE(ShippingState)....etc.

 

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.

 

Thanks!

Mike