0

Hi I am submitting record for approval in test class, and then again I am approving it. Still the status is showing as pending. Can anyone help here?

public static testMethod void ContractTestMethod()
{

   Account acc = new Account(Name = 'TestAcc');
    Insert acc;

    Contract c = new Contract(AccountId = acc.Id,
                              Name = 'TestContract',
                             );
    Insert c;

    Approval.ProcessSubmitRequest req = new Approval.ProcessSubmitRequest();
    req.setObjectId(c.Id);

    //Submit the approval request
    Approval.ProcessResult result = Approval.Process(req);

    List<ProcessInstanceWorkitem> workItems = [
        SELECT Id, ProcessInstanceId 
        FROM ProcessInstanceWorkitem 
        WHERE ProcessInstance.TargetObjectId = :c.ID 
    ];


    List<Approval.ProcessWorkitemRequest> requests = new List<Approval.ProcessWorkitemRequest>();
    for(ProcessInstanceWorkitem workItem : workItems){
        Approval.ProcessWorkitemRequest req1 = new Approval.ProcessWorkitemRequest();
        req1.setWorkitemId(workItem.Id);
        //Valid values are: Approve, Reject, or Removed. 
        //Only system administrators can specify Removed.
        req1.setAction('Approve');
        req1.setComments('Your Comment.');
        requests.add(req1);
    }
    Approval.ProcessResult[] processResults = Approval.process(requests);
    system.debug('*******Approval Status*****'+processResults);


    list<contract> con=new list<contract>();
    con.add(c);

   TestNow.updateLastApproverOnContract(con);
    }
  • What you have tried so far? – Santanu Boral Mar 7 '19 at 18:00
  • Can you query ``ProcessInstanceWorkitem` with the processInstance id's that you have approved? – Pranay Jaiswal Mar 7 '19 at 18:01
  • I have quried it is in still pending state. @pranay – Vivian Mar 7 '19 at 19:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.