This global method retrieved the information of the asynchronous apex job running in the backend for a business object.

You can retrieve current information of the following apex jobs:

  • Create and activate Agreement
  • Clone proposal and agreement
  • Finalize proposal and agreement
  • Accept proposal
  • Create and accept Order
  • Asynchronous cart pricing 


APISignature
getBatchJobInfoForContext

static Apttus_Config2.CPQStruct.JobInfo getBatchJobInfoForContext(Id ctxObjectId)

Request Parameter
NameTypeRequired?Description
ctxObjectIdIDYesThe Id of the business object like proposal or agreement.
Response Data Object - Apttus_Config2.CPQStruct.JobInfo
FieldTypeDescription
ChildJobsListThe child apex jobs that are associated the original apex jobs.
CompletedDateDatetimeThe date and time when the original or child of the apex job was completed.
ExtendedStatusStringThe messages of errors encountered during apex job runtime.
JobIdIdThe apex job Id
JobNameString

The functional and apex job name in the following format:

<Function name>:<apex job name>

JobTypeString

The type of the apex job. For example, queueable and batchable.

ParentJobIdIdThe Id of the given apex job's parent
PercentCompleteIntegerThe percentage of completion of the apex job at the time when global method was invoked.
StatusString

The status of the parent apex job. The following are the possible values:

  • Processing
  • Completed
  • Failed
  • Aborted
SubmittedDateDatetimeThe date and time when the apex job was submitted.


Code Sample

The above global method can be used in API polling in a specific interval to retrieve the current status of the apex jobs running in the backend. For example, you are building a custom Lightning Web Component to show the live progress bar with the percentage of completion and status of the job in the proposal object. The Below apex controller calls the global method and returns the percentage of completion and the status to the UI controller to handle.

public static final String STATUS_FAILED = 'Failed';
public static final String STATUS_API_CALLOUT_ERROR = 'APIError';
	public static final String GENERIC_JOB_NAME = 'asynchronous';
    	public static Boolean isLightning = null;
    	public static Boolean isDeployedInPackage = null;
	public ProposalBannerController(ApexPages.StandardController stdController) {
	}
	/**
	 * Gets the async job info for the propoal
	 * @param proposalID id of the quote/proposal record 
	 * @return map of status, percentcomplete and jobId to the LWC.
	 */
	@AuraEnabled
	public static Map<String,Object> getBatchJobInfo(String proposalID){
		Map<String,Object> responseDO = new Map<String,Object>();
		String functionalJobName = GENERIC_JOB_NAME;
		String asyncClassName = '';
		try {
			Apttus_Config2.CPQStruct.JobInfo parentJobInfo = Apttus_CPQAPI.BatchUpdateService.getBatchJobInfoForContext (proposalID);
			responseDO.put('parentJobStatus', parentJobInfo.Status);
			responseDO.put('parentPercentComplete', parentJobInfo.PercentComplete);
			responseDO.put('parentJobId', parentJobInfo.JobId);

			if (parentJobInfo.JobName != null) {
				functionalJobName = parentJobInfo.JobName.split(':')[0];
				asyncClassName = parentJobInfo.JobName.split(':')[1] + ':';
			}
			responseDO.put('jobName', functionalJobName);

			if(parentJobInfo.status == STATUS_FAILED){
				responseDO.put('ExtendedStatus', asyncClassName + parentJobInfo.ExtendedStatus);

			}
		} catch (Exception e) {
			// We have to ignore this error in LWC
			responseDO.put('ExtendedStatus', e.getMessage());
			responseDO.put('parentJobStatus', STATUS_API_CALLOUT_ERROR);
 			responseDO.put('jobName', GENERIC_JOB_NAME);
		}

		return responseDO;
	}
}
CODE