Skip to content

Latest commit

 

History

History
232 lines (140 loc) · 5.17 KB

File metadata and controls

232 lines (140 loc) · 5.17 KB

This class provides a way for developers to create a process of Queueable classes. This implementation facilitates the handoff of data into the overarching process and from one process step to the next. While functionally similar to the way a 'Promise' pattern allows you chain async methods together. However, a true Promise pattern resolves itself, one way or another, within the same transaction. Therefore, this is not a true Promise pattern, but an elegant way to logically chain Salesforce Queueables together. As a Developer, you'll need to extend this class, implementing the necessary execute method. Your execute method will be invoked asynchronously as part of a Queueable. You can then chain additional Queueables together using the then method provided by this class. <br> As each 'step' of the chain is completed the transaction finalizer will be constructed with the remaining steps and any passthrough data you specify. Passthrough data allows you to pass data between steps.

Implements

Queueable, Database.AllowsCallouts

Fields

processSteps

Signature

public processSteps

Type

List<QueueableProcess>


dataPassthrough

Signature

public dataPassthrough

Type

Object


queueableContextHistory

Signature

public queueableContextHistory

Type

List<QueueableContext>


finalizerContextHistory

Signature

public finalizerContextHistory

Type

List<FinalizerContext>


defaultHandleExceptionCalled

TESTVISIBLE

Signature

private static defaultHandleExceptionCalled

Type

Boolean

Constructors

QueueableProcess()

SUPPRESSWARNINGS

this is a constructor that is used by extension classes;

Signature

protected QueueableProcess()

Methods

then(toAdd)

This method provides a syntactic sugar for adding a new QueueableProcess to the chain.

Signature

public QueueableProcess then(QueueableProcess toAdd)

Parameters

Name Type Description
toAdd QueueableProcess An instance of a class that extends this QueueableProcess class and implements the execute method.

Return Type

QueueableProcess

Returns a Queueable Process instance that can be used to chain additional QueueableProcess instances.


start()

This method starts the QueueableProcess chain. It's the entry point for the process.

Signature

public Id start()

Return Type

Id

Id - Id of the Enqueued job.


start(initialPassthrough)

This method starts the QueueableProcess chain. It's the entry point for the process.

Signature

public Id start(Object initialPassthrough)

Parameters

Name Type Description
initialPassthrough Object Object - this is the initial passthrough data that will be passed to the first
QueueableProcess in the chain.

Return Type

Id

Id - Id of the Enqueued job.


execute()

This must be implemented by extending classes. Developers - implement this method with the work you want executed asynchronously.

Signature

public abstract void execute()

Return Type

void


handleException(incomingException)

this is a default implementation of an handleError method. It's called by the finalizer if the developer doesn't implement their own handleError method. Developers can write per-step error handling by implementing their own handleError method as public override void handleError(Exception incomingException)

Signature

public virtual void handleException(Exception incomingException)

Parameters

Name Type Description
incomingException Exception Exception - the exception that was thrown during execution.

Return Type

void


execute(context)

This is required by the Queueable interface. It's the essence of how the QueueableProcess pattern is implemented in Apex.

Signature

public virtual void execute(QueueableContext context)

Parameters

Name Type Description
context QueueableContext QueueableContext - dependency injected by Salesforce at execution time.

Return Type

void