QueueableDuplicateSignature.Builder Class

Build a unique signature for your queueable job using this inner builder class. The build() class method builds a QueueableDuplicateSignature object, with input from the addId(), addInteger(), and addString() methods. Use the DuplicateSignature property in the AsyncOptions class to store the queueable job signature. Enqueue your job by using the System.enqueueJob() with the AsyncOptions parameter.

Namespace

System

Examples

This example builds the async job signature with UserId and the string MyQueueable.

1AsyncOptions options = new AsyncOptions();
2options.DuplicateSignature = new System.QueueableDuplicateSignature.Builder()
3                                .addId(UserInfo.getUserId())
4                                .addString('MyQueueable')
5                                .build();
6try {
7    System.enqueueJob(new MyQueueable(), options);
8} catch (DuplicateMessageException ex) {
9    //Exception is thrown if there is already an enqueued job with the same signature
10    Assert.areEqual('Attempt to enqueue job with duplicate queueable signature',
11        ex.getMessage());
12}

This example builds the async job signature using ApexClass Id and the hash value of an sObject.

1AsyncOptions options = new AsyncOptions();
2options.DuplicateSignature = new QueueableDuplicateSignature.Builder()
3                                .addInteger(System.hashCode(someAccount))
4                                .addId([SELECT Id FROM ApexClass 
5                                     WHERE Name='MyQueueable'].Id)
6                                .build();
7System.enqueueJob(new MyQueueable(), options);

QueueableDuplicateSignature.Builder Methods

The following are methods for QueueableDuplicateSignature.Builder.

addId(inputId)

Adds an ID to build a unique signature for a queueable job. You can then enqueue the job by using the signature as the AsyncOptions parameter to System.enqueueJob().

Signature

public System.QueueableDuplicateSignature.Builder addId(Id id)

Parameters

inputId
Type: Id

addInteger(inputInteger)

Adds an integer to build a unique signature for a queueable job. You can then enqueue the job by using the signature as the AsyncOptions parameter to System.enqueueJob().

Signature

public System.QueueableDuplicateSignature.Builder addInteger(Integer i)

Parameters

inputInteger
Type: Integer

addString(inputString)

Adds a string to build a unique signature for a queueable job. You can then enqueue the job by using the signature as the AsyncOptions parameter to System.enqueueJob().

Signature

public System.QueueableDuplicateSignature.Builder addString(String s)

Parameters

inputString
Type: String

build()

Builds a unique signature for a queueable job. You can then enqueue the job by using the signature as the AsyncOptions parameter to System.enqueueJob().

Signature

public System.QueueableDuplicateSignature build()

getMaxSize()

Gets the maximum size of the queueable job signature in bytes.

Signature

public Integer getMaxSize()

Return Value

Type: Integer

getRemainingSize()

Gets the remaining size of the queueable job signature in bytes, after subtracting what is already used by the signature from the maximum allowed number.

Signature

public Integer getRemainingSize()

Return Value

Type: Integer

getSize()

Gets the size of the queueable job signature in bytes.

Signature

public Integer getSize()

Return Value

Type: Integer