Is there a way to roll back the changes (data) if the record is rejected by the approver using standard approval process in salesforce? I've checked and it seems there is no OOB to do this. Is trigger the only way to roll back the record data in this case? For example: Contact record with email ([email protected]) > Email modified (as [email protected]) > record sent for approval > approver "Rejects" it. Now i want the contact record with data (rolled back) as [email protected]
If you want to do a rollback of a large number of fields (or actually an entire object) you can't use workflow or triggers anymore but need to use APEX in combination with a datastore to store the old data that could be needed to roll back.
I'd suggest one of these solutions:
- create a full copy of the record and store it in another place, invisible for the end user. If you have an object with public readability, you might even need to create a separate custom object to store the data. Then add some APEX to create and cleanup the pseudo-object. Then have the APEX called by a trigger which in turn is triggered by an approval process.
- create a long text field on the object and use APEX to write a JSON string of the object into the text field. Then if the approval is rejected, use APEX to generate back the old record from the JSON string. The triggering happens the same way as for #1.
2 is easier more lightweight but you could run out of space in your long text field if there's a lot of data to save..