---
schema_version: "1"
id: d49c591d108175e1ea00700e9d848640b4f808dde76509dbb771c4949540cd98
title: Abort a Job Chain
collection: legacydeveloper
version: current
locale: en-us
portal_url: https://docs.salesforce.com/legacydeveloper/current/en-us/retail_api/cgtpm_abort_job_chain.md
canonical_url: https://developer.salesforce.com/docs/atlas.en-us.retail_api.meta/retail_api/cgtpm_abort_job_chain.htm
source_site: developer.salesforce.com
content_type: documentation
content_hash: 8a72475d2957cbf724fd18a8fa158b138fdc1af36d8dbabecbc23e6b71ac237f
description: Stops the running job chain worker for a sales org.
---
# Abort a Job Chain

Stops the running job chain worker for a sales org.

Use this feature when a job chain is stuck or when a large number of jobs was scheduled by mistake. A job chain is a set of processing jobs that depend on each other. CG Cloud Processing Services runs job chains outside Salesforce. A job chain worker picks up the jobs and runs them in order. Aborting a job chain ends the job chain worker.

Aborting takes two steps. First, get the job identifier of the running job chain worker. Then, delete the job by its identifier.

Both steps use the global <namespace>.OffPlatformCallout class. Pass the sales org to the constructor. The sales org is required. For more information about the effect of the sales org, see [Abort Behavior](https://developer.salesforce.com/docs/atlas.en-us.retail_api.meta/retail_api/cgtpm_abort_job_chain_behavior.htm "Understand what an abort stops and what it leaves unchanged.").

## Step 1. Get the Job Identifier

This request returns the job identifier of the running job chain worker.

**Resource**

JOBCHAINWORKER\_ABORT\_GET\_JOB\_ID

**Available version**

68.0

**Apex Request Example**

String endpointName = 'JOBCHAINWORKER\_ABORT\_GET\_JOB\_ID';
String salesOrg = '9999';
<namespace>.OffPlatformCallout request = new <namespace>.OffPlatformCallout(endpointName, salesOrg);
// This request has no path variables and no request body.
<namespace>.OffplatformCalloutResponse response = request.execute(
    <namespace>.TransactionHandler.getTransactionIdentifier(),
    null,
    null
);
if (response.status != 200) {
    // A 404 status means that no job chain worker can be aborted.
    return;
}
Map<String, Object\> body = (Map<String, Object\>) JSON.deserializeUntyped(response.result);
String k8sJobId = (String) body.get('k8sJobId');

The response body contains the k8sJobId, jobState, and launchId fields. Use the value of k8sJobId in step 2.

## Step 2. Abort the Job

This request deletes the job and ends the job chain worker.

The resource path contains the :k8sjobid variable. To set its value, pass a map to execute(). The map key must be k8sjobid, with the same spelling and case. If the key does not match, the variable is not replaced and the request fails.

**Resource**

JOBCHAINWORKER\_ABORT\_DELETE\_JOB

**Available version**

68.0

**Apex Request Example**

String endpointName = 'JOBCHAINWORKER\_ABORT\_DELETE\_JOB';
String salesOrg = '9999';
String k8sJobId = 'JOB\_ID\_FROM\_STEP\_1';
<namespace>.OffPlatformCallout request = new <namespace>.OffPlatformCallout(endpointName, salesOrg);
<namespace>.OffplatformCalloutResponse response = request.execute(
    <namespace>.TransactionHandler.getTransactionIdentifier(),
    new Map<String, String\>{ 'k8sjobid' => k8sJobId },
    null
);
if (response.status != 200) {
    // A 404 status means that the job no longer exists.
    return;
}

The response body contains the message, k8sJobId, and abortedAt fields.

The response object has the following properties.

- status is an Integer that holds the HTTP status code.
- result is a String that holds the response body.
- message is a String that holds the status message.

- **[Abort Behavior](https://developer.salesforce.com/docs/atlas.en-us.retail_api.meta/retail_api/cgtpm_abort_job_chain_behavior.htm)**  
    Understand what an abort stops and what it leaves unchanged.
- **[Abort Endpoint Configuration](https://developer.salesforce.com/docs/atlas.en-us.retail_api.meta/retail_api/cgtpm_abort_job_chain_endpoints.htm)**  
    Review the endpoint records that route the abort requests.
- **[Troubleshoot an Abort](https://developer.salesforce.com/docs/atlas.en-us.retail_api.meta/retail_api/cgtpm_abort_job_chain_troubleshooting.htm)**  
    Learn why an abort request can fail and how to check that a job chain stopped.
- **[Update Batch Run Status Records After an Abort](https://developer.salesforce.com/docs/atlas.en-us.retail_api.meta/retail_api/cgtpm_abort_job_chain_update_status.htm)**  
    Change the state of Batch Run Status records that stay in the Running state after an abort.