Skip to main content
This example builds a three-step Job Group end to end. It shows how steps depend on each other, how an error appears, and how a rerun succeeds after you fix the data.

Prerequisites

  • You have the FC Platform - Manage Async Jobs permission set.
  • You can create Accounts and Contacts in the org.
  • You can deploy Apex classes to your org (Setup, an IDE, or a deployment).
  • You understand the basics from Async Job Coordinator Overview.

The Goal

The Job Group is named Prospect Account Enrichment. Its description is “Rates Prospect Accounts, creates a primary Contact for Hot prospects, and stamps a summary on each Account.” All three steps use a Batch Size of 200 and leave Parallel off.

Why Await Is On for Steps 1 and 2

Step 2 only finds Hot Accounts, so it needs the ratings from step 1. Step 3 counts Contacts, so it needs the Contacts from step 2. Sequence alone does not make a step wait, so Await on steps 1 and 2 holds the next step until the previous one finishes. Step 3 has no later step, so it does not need Await.

Demo Data

Create these Accounts with Type set to Prospect: Harbor Light Society has no Website on purpose. It makes step 2 fail so you can see how errors appear.

The Apex Classes

Each class implements FCORE_BASE.JobExecutor, is declared global, and uses with sharing. Each one implements both the regular and retry methods. See For Developers for the interface.

Step 1: AccountRatingJob

This class reports a failed record through recordErrors. It updates with allOrNone set to false, so one bad record does not fail the whole batch. In executeRetry, it reports only successes.

Step 2: PrimaryContactJob

This class reports an Account with no Website as a record error. That error is what triggers the retry.

Step 3: AccountDescriptionJob

This class returns null from execute because there is nothing for the coordinator to post-process.
Deploying to production requires test coverage. This class covers all three steps and the retry methods.

Build the Job Group

Follow Managing Job Groups with these values.
1

Create the group

Open the Job Groups tab from the App Launcher and click New. Enter the Name Prospect Account Enrichment and the description above. Leave Version at 1 and Is Active off.
2

Add the three steps

Click Add New Definition three times. Fill in the rows from the table in The Goal, and turn Await on for steps 1 and 2.
The Job Definitions section with Update Account Rating, Create Primary Contacts and Stamp Account Descriptions, each with its Apex class and Batch Size 200, and Await on for steps 1 and 2

The three example steps

3

Save and activate

Click Save. Then turn Is Active on, leave Frequency as None (you start the run from code), and click Save again.

Run the Job Group

To start a run, either set a Frequency and wait for the schedule, or start one from code. To start from code, open the Developer Console, click Debug, then Open Execute Anonymous Apex Window. Run the following:
The run takes a few seconds with this demo data.

Read the First Run

Open the Job Group and click Last Run.
  • Status: Completed with Errors
  • Number Of Errors: 1
The Job Run Stages show this: The Job Error on Harbor Light Society reads Website is required to create the primary Contact.
Job Run JR-000000 with Status Completed with Errors, Number Of Errors 1, one Job Error, and five Job Run Stages

The first run: Completed with Errors

Job Error JE-000000 for the Create Primary Contacts step with the message Website is required to create the primary Contact

The Job Error for Harbor Light Society

Fix the Account and Rerun

1

Fix the data

Open the Harbor Light Society Account, set Website to www.harborlight.example.com, and click Save.
2

Rerun

Run the same snippet from Run the Job Group again in Execute Anonymous.

Read the Clean Result

Open the Job Group and click Last Run, which now points to the second run.
  • Status: Completed Successfully
  • Number Of Errors: 0
  • Job Run Stages: the three regular stages only. No retry stages were needed.
Harbor Light Society now has a Contact and the Description “Rating: Hot. Contacts: 1.”

Limitations and Common Pitfalls

  • Leaving Await off on step 1 or 2. A later step can start before the earlier one finishes and find no records to process.
  • Failing to report successes in a retry. If executeRetry does not list the successful record Ids, their Job Errors stay on the run.
  • Reporting errors from executeRetry. This logs additional Job Errors instead of keeping the original ones.
  • Pasting the classes without the global keyword. The class does not appear in the Apex Class dropdown.
  • Editing the group while it is active. Deactivate and save first. See Managing Job Groups.

Managing Job Groups

Create, schedule, and change Job Groups.

Monitoring Job Runs

Read statuses, stages, and errors.