i have a test method,creating a record then submitting to the approval by using process builder,then i have to approve the approval request,
@isTest
private class RequireRejectionCommentTest
{
private static testmethod void testRejectionWithoutComment()
{
Id testWorkItemId = generateObject();
Approval.ProcessWorkitemRequest testRej = new Approval.ProcessWorkitemRequest();
testRej.setComments('');
testRej.setAction ('Reject');
testRej.setWorkitemId(testWorkItemId );
try
{
Approval.ProcessResult testRejResult = Approval.process(testRej);
system.assert(true, 'A rejection with no comment should cause an exception');
}
catch(DMLException e)
{
system.assertEquals('Please provide a rejection reason!',
e.getDmlMessage(0),
'Please provide a rejection reason!');
}
}
private static Id generateObject()
{
TR_Currency_Approval__c testIS = new TR_Currency_Approval__c();
testIS.Active__c=true;
insert testIS;
return Id;
}
}
in the generateObject method i need to get the id of the approval request submitted by process builder. if we are submitting the record for approval programmatically,we used to wrte something like this
Approval.ProcessSubmitRequest testReq = new Approval.ProcessSubmitRequest(); testReq.setObjectId(testIS.Id);
Approval.ProcessResult reqResult = Approval.process(testReq);
return reqResult.getNewWorkitemIds()[0];
I struck here please help me out guys, Thanks in advance