Step
Step should be used to describe/implement single atomic function.
Step(String asyncProcessClassName)
Constructor.
Parameters:
- asyncProcessClassName - functional step class full name
Step(String asyncProcessClassName, Integer recordsThresholdToRunAsync)
Constructor.
Parameters:
- asyncProcessClassName - functional step class full name recordsThresholdToRunAsync - minimal number of records added to async context which need to be executed in the async context.
Step(String asyncProcessClassName, String executionMethod, Integer recordsThresholdToRunAsync, Boolean stroeInTheQueue)
Constructor.
Parameters:
- asyncProcessClassName - functional step class full name.
- executionMethod - determines execution strategy.
- recordsThresholdToRunAsync - minimal number of records added to async context which need to be executed in the async context.
- storeInTheQueue - if true - stores async process request in the AsyncJob__c queue.
initialize()
Additional step initialization.
initRecordProcessing(Object record, Object optionalOldRecord)
Method is executed for records for which initRecordProcessing method returns true. Should be used to modify newRecord fields if all required data are available for use ModificationContext to modify related data. DML and Queries are not allowed in this method. Between initRecordProcessing and finishRecordProcessing. Step Handler uses Loader to load data into the DataStore.
Parameters:
- record - SObject instance, this record needs to be modified.
- optionalOldRecord - old SObject instance, this record should not be modified
Return:
True if the finishRecordProcessing method needs to be executed for newRecord record.
finishRecordProcessing(Object record, Object optionalOldRecord)
Method is executed for records for which initRecordProcessing method returns true. Should be used to modify newRecord fields if all required data are available for use ModificationContext to modify related data. DML and Queries are not allowed in this method. Between initRecordProcessing and finishRecordProcessing Step Handler uses Loader to load data into the DataStore.
Parameters:
- record - SObject instance, this record needs to be modified.
- optionalOldRecord - old SObject instance, this record should not be modified
finishSyncProcess(List records, List optionalOldRecords)
Finalizes sync process. newRecords and oldRecords parameters contain records added by addToSyncFinish method. This method will always run even if newRecords is empty.
executeAsyncProcess(Map<String, AsyncJobInfo> asyncJobByRecordKey)
Runs async process. Override it if you want to run logic in the async context.
Parameters:
- asyncJobByRecordKey- Async job infos by record key.
prepareAsyncDataStore(Map<String, AsyncJobInfo> asyncJobByRecordKey, DataStore store)
When step is executed in async context, the DataStore is empty. You can use this method to prepopulate DataStore data.
Parameters:
- asyncJobByRecordKey- Async job infos by record key.
- store - data store.
initialize(ModificationContext modificationContext, DataStore store)
Initialize Step.
Parameters:
- modificationContext- modification context related with step handler
- store - data store related with step handler.
finish()
Finishes the asynchronous job request and returns the result.
Return:
An array of AsyncJobError objects, representing the result of the asynchronous job request.
execute(Map<String, AsyncJobInfo> asyncJobsByRecordKey, ModificationContext ctx)
AsyncJob implementation for step purpose.
Parameters:
- asyncJobsByRecordKey - AsyncJobInfo by recordKeys related with async process
- ctx - ModificationContext class.
Return:
AsyncJobError instances.
addAsyncProcessingError(String recordKey, String errorMessage)
Adds an error message for the specified record key to the list of asynchronous processing errors.
Parameters:
- recordKey - The unique identifier for the record that encountered the error
- errorMessage - A description of the error that occurred during processing
addAsyncProcessingCriticalError(String recordKey, String errorMessage)
Adds a critical error message for the async processing errors for the given record.
Parameters:
- recordKey - The unique identifier for the record that encountered the error
- errorMessage - A description of the error that occurred during processing
addAsyncProcessingError(String recordKey, String errorMessage, Boolean isCritical)
Adds an error to the errorResults Map for asynchronous job.
Parameters:
- recordKey - The unique identifier for the record that encountered the error
- errorMessage - A description of the error that occurred during processing
- isCritical - A boolean indicating whether the error is critical or not.
addToSyncFinish(Object record, Object optionalOldRecord)
Adds a record and its optional old record to the list of records to be finished during the sync process.
Parameters:
- record - The record to be finished during the sync process
- optionalOldRecord - The optional old record to be finished during the sync process. Can be null.
addAsyncJob(String recordKey, String payLoad)
Adds an asynchronous job to the list of jobs to be processed.
Parameters:
- recordKey - The key that identifies the record to be processed.
- payLoad - The payload to be processed for the record.
addAsyncJob(String recordKey)
Adds an asynchronous job to the list of jobs to be processed.
Parameters:
- recordKey - The key that identifies the record to be processed.
addDelayedAsyncJob(String recordKey, Datetime executionTime)
Adds an asynchronous job to the list of jobs to be processed.
Parameters:
- recordKey - The key that identifies the record to be processed.
- executionTime - The execution time for the job.
cancelAsyncRequest(String recordKey)
Cancels async process for provided record.
Parameters:
- recordKey - The key that identifies the record to be canceled.
getConfig()
Returns the StepFunctionConfig object. If the additionalConfig is null, it calls the buildStepFunctionConfig method of the StepFunctionsProvider class, passing in the stepConfigName as an argument. The buildStepFunctionConfig method returns a StepFunctionConfig object, which is then assigned to additionalConfig
Return:
The StepFunctionConfig object represents the configuration for a step.
getContext()
Returns modification context.
Return:
ModificationContext instance.
getStore()
Returns a DataStore.
Return: DataStore instance.
getAsyncRequest()
Returns async request description.
Return:
AsyncRequest instance which describes async request
getStepName()
Returns modification context.
Return:
ModificationContext instance.
isNew(Object record, Object optionalOldRecord)
Check if the record is new.
Parameters:
- record - the current record to be evaluated
- optionalOldRecord - the old record to compare against.
Return:
True if the old record is null, indicating that the current record is new, false otherwise.
isChanged(SObject record, SObject optionalOldRecord, SObjectField field)
Check if the record has been changed.
Parameters:
- record - the current record to be evaluated
- optionalOldRecord - the old record to compare against.
- field - field that is verified
Return:
True if the field has been changed in newRecord.
isNewOrChanged(SObject record, SObject optionalOldRecord, SObjectField field)
Check if the record has been changed or is new.
Parameters:
- record - the current record to be evaluated
- optionalOldRecord - the old record to compare against.
- field - field that is verified
Return:
True if the field has been changed in newRecord or newRecord is new.