I've followed instructions here to submit records into an approval process. This seems to be running fine without errors, and my debug logs have confirmed the submission has occured:
16:50:09:101 USER_DEBUG [13]|DEBUG|@@@o.Id: 006m0000005TZs1AAG
16:50:09:101 USER_DEBUG [14]|DEBUG|@@@processName: VP_Approval_Final
16:50:11:677 USER_DEBUG [25]|DEBUG|@@@result.isSuccess: true
16:50:11:677 USER_DEBUG [26]|DEBUG|@@@result.getInstanceStatus: Pending
However, upon navigation to this records page, I'd expect to see the record inserted into an approval flow with approval process history. Instead, I see nothing. What am I doing wrong? The code I'm using is nearly an exact copy/paste of the above link.
private static void runApproval(Opportunity o){
// Create an approval request for the account
Approval.ProcessSubmitRequest req1 =
new Approval.ProcessSubmitRequest();
req1.setObjectId(o.Id);
// Submit on behalf of a specific submitter
req1.setSubmitterId(UserInfo.getUserId());
System.debug('@@@o.Id: ' + o.Id);
System.debug('@@@processName: ' + o.Migration_ProcessName__c);
// Submit the record to specific process and skip the criteria evaluation
req1.setProcessDefinitionNameOrId(o.Migration_ProcessName__c);
req1.setSkipEntryCriteria(true);
// Submit the approval request
Approval.ProcessResult result = Approval.process(req1);
// Verify the result
System.assert(result.isSuccess());
System.debug('@@@result.isSuccess: ' + result.isSuccess());
System.debug('@@@result.getInstanceStatus: ' + result.getInstanceStatus());
System.assertEquals(
'Pending', result.getInstanceStatus(),
'Instance Status'+result.getInstanceStatus());
if(o.Migration_Approve__c){
// 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.setAction('Approve');
req2.setNextApproverIds(new Id[] {UserInfo.getUserId()});
// Use the ID from the newly created item to specify the item to be worked
req2.setWorkitemId(newWorkItemIds.get(0));
// Submit the request for approval
Approval.ProcessResult result2 = Approval.process(req2);
// Verify the results
System.assert(result2.isSuccess(), 'Result Status:'+result2.isSuccess());
System.assertEquals(
'Approved', result2.getInstanceStatus(),
'Instance Status'+result2.getInstanceStatus());
}
}