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

Approval Process



I am working on an Approval Process and I would like to know who has approved or Rejected using Apex code.







Try the below code snippet as reference:


..................Trigger example.................
trigger OpportunitySubmitForApproval on Opportunity (after update) {

for (Integer i = 0; i <; i++) {

if (Trigger.old[i].Probability < 30 &&[i].Probability >= 30) {

// create the new approval request to submit
Approval.ProcessSubmitRequest req = new Approval.ProcessSubmitRequest();
req.setComments('Submitted for approval. Please approve.');
// submit the approval request for processing
Approval.ProcessResult result = Approval.process(req);
// display if the reqeust was successful
System.debug('Submitted for approval successfully: '+result.isSuccess());




..........................................Apex controller example.................................

public class TestApproval {
void submitAndProcessApprovalRequest() {
// Insert an account

Account a = new Account(Name='Test',annualRevenue=100.0);

insert a;

// Create an approval request for the account

Approval.ProcessSubmitRequest req1 =
new Approval.ProcessSubmitRequest();
req1.setComments('Submitting request for approval.');

// Submit the approval request for the account

Approval.ProcessResult result = Approval.process(req1);

// Verify the result


'Pending', result.getInstanceStatus(),
'Instance Status'+result.getInstanceStatus());

// Approve the submitted request

// First, get the ID of the newly created item

List<Id> newWorkItemIds = result.getNewWorkitemIds();

// Instantiate the new ProcessWorkitemRequest object and populate it

Approval.ProcessWorkitemRequest req2 =
new Approval.ProcessWorkitemRequest();
req2.setComments('Approving request.');
req2.setNextApproverIds(new Id[] {UserInfo.getUserId()});

// Use the ID from the newly created item to specify the item to be worked


// Submit the request for approval

Approval.ProcessResult result2 = Approval.process(req2);

// Verify the results

System.assert(result2.isSuccess(), 'Result Status:'+result2.isSuccess());

'Approved', result2.getInstanceStatus(),
'Instance Status'+result2.getInstanceStatus());



Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved. 




Thanks for a quick reply.


I have seen the standard approval class and code that we can use to submit an approval process for a given object


However, my scenario is that I have to get the actual approver of a given record (which is already Approved or Rejected). Hence, I do not have to submit the record for approval but merely retrieve the person who as approved the record.


Hope this clarifies the scenario in detail.