With this API, you can submit an approval context with comments JSON. 

submitForApprovalsWithComments

Request Parameters
NameTypeRequired?Description

sObjectId

IDYesID of the approval context object.

sObjectType

StringYesType of the approval context object.
commentsJSONStringYesA JSON representation of the SubmissionComments object.
Response Parameter
NameTypeDescription
resultBooleanReturns true if the API is executed successfully.

Code Sample

The sample below enables you to set process and step level comments.

// create process level submission comments JSON structure
SubmissionComments commentsInfo = new SubmissionComments();
commentsInfo.commentsLevel = SubmissionComments.PROCESS_LEVEL_COMMENTS;
commentsInfo.commentsCount = 1;
commentsInfo.processName = 'ProcessName';
commentsInfo.processCommentLabel = 'ProcessLabel';
commentsInfo.processCommentMandatory = false;
commentsInfo.processComment = 'Here is my comment';
		
String submitCommentsJSON = commentsInfo.toJSON();
/* submitCommentsJSON =
{
  "stepCommentList" : [],
    "processName" : "ProcessName",
    "processCommentMandatory" : false,
    "processCommentLabel" : "ProcessLabel",
    "processComment" : "Here is my comment",
    "commentsLevel" : "Process",
    "commentsCount" : 1
}
*/	
//  get JSON representation for submission comments
String submitCommentsJSON = commentsInfo.toJSON();
// submit with comments
ApprovalsWebService.submitForApprovalsWithCommentsJSON(SObjectConstants.SOBJECT_TYPE_AGREEMENT, 'a013l00000sR4iPAAS', submitCommentsJSON);	




// create step level submission comments JSON structure
SubmissionComments commentsInfo = new SubmissionComments();
commentsInfo.commentsLevel = SubmissionComments.STEP_LEVEL_COMMENTS;
commentsInfo.commentsCount = 3;
// create step comment
SubmissionComments.StepComment stepComment1 = new SubmissionComments.StepComment();
stepComment1.stepName = 'User Assignee';
stepComment1.stepCommentLabel = 'GS_Business_Justification';
stepComment1.stepComment = 'This is comment 1';
commentsInfo.addStepComment(stepComment1);
// create step comment
SubmissionComments.StepComment stepComment2 = new SubmissionComments.StepComment();
stepComment2.stepName = 'Queue Assignee';
stepComment2.stepCommentLabel = 'GS_Deal_Strategy';
stepComment2.stepComment = 'This is comment 2';
commentsInfo.addStepComment(stepComment2);
// create step comment
SubmissionComments.StepComment stepComment3 = new SubmissionComments.StepComment();
stepComment3.stepName = 'Role Assignee';
stepComment3.stepCommentLabel = 'GS_Supporting_Information';
stepComment3.stepComment = 'This is comment 3';
commentsInfo.addStepComment(stepComment3);

/* submitCommentsJSON = 
{
  "stepCommentList" : [ {
    "stepName" : "User Assignee",
    "stepCommentLabel" : "GS_Business_Justification",
    "stepComment" : "This is comment 1"
  }, {
    "stepName" : "Queue Assignee",
    "stepCommentLabel" : "GS_Deal_Strategy",
    "stepComment" : "This is comment 2"
  }, {
    "stepName" : "Role Assignee",
    "stepCommentLabel" : "GS_Supporting_Information",
    "stepComment" : "This is comment 3"
  } ],
  "processName" : null,
  "processCommentMandatory" : false,
  "processCommentLabel" : null,
  "processComment" : null,
  "commentsLevel" : "Step",
  "commentsCount" : 3
}
*/	
//  get JSON representation for submission comments
String submitCommentsJSON = commentsInfo.toJSON();
// submit with comments
ApprovalsWebService.submitForApprovalsWithCommentsJSON(SObjectConstants.SOBJECT_TYPE_AGREEMENT, 'a013l00000sR4iPAAS', submitCommentsJSON);
CODE