[SalesForce] Is it possbile to remove approval history based on criteria

I have an approval process on a custom object. Once the record has been approved, Status will be changed to Approved and record locked.

If the user changes Amount field, the Status will be changed to pending and it should go through the approval process again. Now the user submits the record again for approval it goes through the process.

Is it possible to remove the approval history if the status has changed?

Best Answer

If you are just looking to remove the Approval History records related to the original approval when it needs to be submitted for approval the second time, no that is not possible. I would argue that you really shouldn't want it to be deleted (since it actually shows the true history then).

As @doga suggested, you can hide or display it with different page layouts. If you are really set on removing old history from the page, you could override your page with Visualforce and then create your own related list by querying the objects. You just query for the related list and then filter it out in your controller before throwing it onto the page. For instance, if you wanted to get the related Approval History on an account:

SELECT
    (SELECT 
        Id, IsPending, ProcessInstanceId, TargetObjectId, StepStatus, OriginalActorId,
        ActorId, RemindersSent, Comments, IsDeleted, CreatedDate, CreatedById, SystemModstamp 
    FROM ProcessSteps)
FROM
    Account a

Notice how ProcessSteps is the name of the relationship. The actual object is ProcessInstanceHistory.

You can use this list then and filter out the records you don't want to display on your page. I wouldn't suggest this, but it is an option if needed.