You need to sign in to do that
Don't have an account?

Need to capture approval process comments on custom field
I have a requirement to capture the approval process comments on a custom field we just have one step for approval process. Can some one guide me to achieve the same.
You can do it in many ways. Here are coupe of options
Option1: Use apex to update object. See if you can run the code with in governor limits.
Here is the pseudo code to get you started.
Option2: Export the process instance data from above query and manually create your object import file by filling comments field from process instance data.
"process definition Id"?
//Get all approval process records from an approval process definition
List<ProcessInstance> instances = [SELECT Id,TargetObjectId,(SELECT Id, StepStatus, Comments FROM Steps) FROM ProcessInstance Where ProcessDefinitionId = '[Your process definition Id]'];
Set<String> objectIds = new Set<String>();
//Create a set of object Ids which has process instance for(ProcessInstance pi:instances){ objectIds.add(pi.TargetobjectId); }
//Query for related records
Map<Id,YOUR_OBJECT__C> yourObjectMap = new Map<Id,YOUR_OBJECT__C>([Select Your_Comments_Field__c from YOUR_OBJECT__C Where Id in:objectIds ]);
//populate object's comment field from approval comments
for(ProcessInstance pi:instances){
for (ProcessInstanceStep step : pi.Steps) { if(step.Status == 'Approved') { yourObjectMap.get(pi.TargetObjectId).Your_Comments_Field__c = step.Comments; } } }
//Update your object
update yourObjectMap.values();
You can query it using
SELECT Id FROM ProcessDefinition
Where State = 'Active' and TableEnumOrId = <Your object API name>