Step Class
The forvendi.Step base class represents a single, atomic functional execution unit within a pipeline. It supports synchronous record processing pipelines, dynamic lazy data loading via DataStore, transactional DML via ModificationContext, and automatic asynchronous execution offloading.
📘 Feature Documentation: For conceptual architecture, configuration rules, and Step Group pipelines, refer to the main Step & Step Groups Documentation.
Description
A Step should be used to encapsulate a single business logic action. Step handlers organize record execution into initialization, data pre-loading, field modification, sync finalization, and async queue offloading.
Constructors
public Step(String asyncProcessClassName)
public Step(String asyncProcessClassName, Integer recordsThresholdToRunAsync)
public Step(String asyncProcessClassName, String executionMethod, Integer recordsThresholdToRunAsync, Boolean storeInTheQueue)Parameters:
asyncProcessClassName: Full developer name of the target async process Apex class.recordsThresholdToRunAsync: Minimal number of records required to shift execution from synchronous to asynchronous context.executionMethod: Strategy name determining asynchronous execution handling.storeInTheQueue: Iftrue, stores the async request in the framework queue object (AsyncJob__c).
Pipeline Lifecycle Methods
initialize()
Override to perform custom step initializations before record processing begins.
Signature:
public virtual void initialize()
public virtual void initialize(forvendi.ModificationContext modificationContext, forvendi.DataStore store)initRecordProcessing(Object record, Object optionalOldRecord)
First processing pass for individual records. Evaluates if a record requires processing and registers data load requests into DataStore.
⚠️ Note: DML operations and SOQL queries are strictly forbidden inside this method.
Signature:
public virtual Boolean initRecordProcessing(Object record, Object optionalOldRecord)Parameters:
record: Current SObject record instance.optionalOldRecord: Prior SObject record state (Trigger.oldMapentry), ornull.
Return Value: Boolean – true if finishRecordProcessing should be executed for this record.
finishRecordProcessing(Object record, Object optionalOldRecord)
Second processing pass executed only for records where initRecordProcessing returned true. Executes field-level logic after DataStore has loaded required context data.
⚠️ Note: Direct DML and SOQL queries are forbidden. Use
ModificationContextto queue changes.
Signature:
public virtual void finishRecordProcessing(Object record, Object optionalOldRecord)finishSyncProcess(List<Object> records, List<Object> optionalOldRecords)
Finalizes synchronous step execution. Processes all records accumulated via addToSyncFinish(). This method runs even if the input record list is empty.
Signature:
public virtual void finishSyncProcess(List<Object> records, List<Object> optionalOldRecords)Asynchronous Execution Methods
executeAsyncProcess(Map<String, AsyncJobInfo> asyncJobByRecordKey)
Main execution hook when step logic runs in an asynchronous background context.
Signature:
public virtual void executeAsyncProcess(Map<String, forvendi.AsyncJobInfo> asyncJobByRecordKey)prepareAsyncDataStore(Map<String, AsyncJobInfo> asyncJobByRecordKey, DataStore store)
Pre-populates the in-memory DataStore when executing in an asynchronous context where the initial cache is empty.
Signature:
public virtual void prepareAsyncDataStore(Map<String, forvendi.AsyncJobInfo> asyncJobByRecordKey, forvendi.DataStore store)execute(Map<String, AsyncJobInfo> asyncJobsByRecordKey, ModificationContext ctx)
Async job handler implementation for step execution.
Signature:
public virtual List<forvendi.AsyncJobError> execute(Map<String, forvendi.AsyncJobInfo> asyncJobsByRecordKey, forvendi.ModificationContext ctx)finish()
Finalizes the asynchronous job request and returns an array of processing errors.
Signature:
public virtual List<forvendi.AsyncJobError> finish()Return Value: List<forvendi.AsyncJobError> – Array of execution errors encountered during processing.
Asynchronous Queue Management
public void addAsyncJob(String recordKey)
public void addAsyncJob(String recordKey, String payload)
public void addDelayedAsyncJob(String recordKey, Datetime executionTime)
public void cancelAsyncRequest(String recordKey)Parameters:
recordKey: Record key identifier.payload: Custom payload string passed to the async job.executionTime: Scheduled execution timestamp for delayed jobs.
Error Handling Methods
public void addAsyncProcessingError(String recordKey, String errorMessage)
public void addAsyncProcessingCriticalError(String recordKey, String errorMessage)
public void addAsyncProcessingError(String recordKey, String errorMessage, Boolean isCritical)Parameters:
recordKey: Record key identifying the record that failed.errorMessage: Error details.isCritical: Iftrue, marks error as critical to prevent automatic framework retry passes.
Context & Helper Methods
addToSyncFinish(Object record, Object optionalOldRecord): Enqueues records into the list processed byfinishSyncProcess().getConfig(): Returns theStepFunctionConfigobject for this step instance.getContext(): Returns the currentModificationContextinstance.getStore(): Returns the activeDataStoreinstance.getAsyncRequest(): Returns theAsyncRequestcontext for the step.getStepName(): Returns the step developer name.
Record Evaluation Utilities
isNew(Object record, Object optionalOldRecord)
Checks if the record is newly created (optionalOldRecord is null).
Signature:
public Boolean isNew(Object record, Object optionalOldRecord)isChanged(SObject record, SObject optionalOldRecord, SObjectField field)
Checks whether the specified field value has changed between record and optionalOldRecord.
Signature:
public Boolean isChanged(SObject record, SObject optionalOldRecord, SObjectField field)isNewOrChanged(SObject record, SObject optionalOldRecord, SObjectField field)
Checks if the record is new OR if the specified field value has changed.
Signature:
public Boolean isNewOrChanged(SObject record, SObject optionalOldRecord, SObjectField field)