Modification Context
The forvendi.ModificationContext class accumulates SObject records, field-level modifications, async tasks, platform events, and lead conversions into a unified transactional unit. It simplifies DML handling and supports bulk execution with granular success tracking.
addToInsert(SObject record)
Adds a single SObject record to the list of pending database insertions.
Signature:
public forvendi.ModificationContext addToInsert(SObject record)Parameters:
record: The SObject record to be inserted.
Return Value: forvendi.ModificationContext – Self-reference for method chaining.
addToAsyncInsert(SObject record) / addToAsyncInsert(SObject[] records)
Adds one or multiple SObject records to an asynchronous database insert queue.
Signature:
public forvendi.ModificationContext addToAsyncInsert(SObject record)
public forvendi.ModificationContext addToAsyncInsert(List<SObject> records)Parameters:
record/records: SObject record or list of records for asynchronous insertion.
Return Value: forvendi.ModificationContext – Self-reference for method chaining.
addToUpdate(SObject record) / addToUpdate(SObject[] records)
Adds one or multiple SObject records to the list of pending updates.
Signature:
public forvendi.ModificationContext addToUpdate(SObject record)
public forvendi.ModificationContext addToUpdate(List<SObject> records)Parameters:
record/records: SObject record or list of records to update.
Return Value: forvendi.ModificationContext – Self-reference for method chaining.
addToAsyncUpdate(SObject record) / addToAsyncUpdate(SObject[] records)
Adds one or multiple SObject records to an asynchronous update queue.
Signature:
public forvendi.ModificationContext addToAsyncUpdate(SObject record)
public forvendi.ModificationContext addToAsyncUpdate(List<SObject> records)Parameters:
record/records: SObject record or list of records for asynchronous update.
Return Value: forvendi.ModificationContext – Self-reference for method chaining.
addModificationToUpdate Methods
Registers field-level modifications for a record to be updated without needing to retrieve or instantiate the entire SObject manually.
Signatures:
public forvendi.ModificationContext addModificationToUpdate(Id recordId, SObjectField objectField, Object value)
public forvendi.ModificationContext addModificationToUpdate(Id recordId, String objectField, Object value)
public forvendi.ModificationContext addModificationToUpdate(Id recordId, Map<SObjectField, Object> changes)
public forvendi.ModificationContext addModificationToUpdate(SObject record, SObjectField objectField, Object value)
public forvendi.ModificationContext addModificationToUpdate(SObject record, Map<SObjectField, Object> changes)Parameters:
recordId/record: Record ID or SObject record instance to modify.objectField: Field API name (String) or field token (SObjectField).value: Target field value.changes: Map of field tokens to target values.
Return Value: forvendi.ModificationContext – Self-reference for method chaining.
addToRemove(SObject record) / addToRemove(SObject[] records)
Adds SObject records to the deletion context.
Signature:
public forvendi.ModificationContext addToRemove(SObject record)
public forvendi.ModificationContext addToRemove(List<SObject> records)Parameters:
record/records: SObject record or list of records to delete.
Return Value: forvendi.ModificationContext – Self-reference for method chaining.
addToAsyncRemove(SObject record) / addToAsyncRemove(SObject[] records)
Adds SObject records to an asynchronous deletion queue.
Signature:
public forvendi.ModificationContext addToAsyncRemove(SObject record)
public forvendi.ModificationContext addToAsyncRemove(List<SObject> records)Parameters:
record/records: SObject record or list of records to delete asynchronously.
Return Value: forvendi.ModificationContext – Self-reference for method chaining.
addToHardRemove(SObject record) / addToHardRemove(SObject[] records)
Adds SObject records for permanent deletion (hard delete).
Signature:
public forvendi.ModificationContext addToHardRemove(SObject record)
public forvendi.ModificationContext addToHardRemove(List<SObject> records)Parameters:
record/records: SObject record or list of records to hard delete.
Return Value: forvendi.ModificationContext – Self-reference for method chaining.
addToConvert(Database.LeadConvert record) / addToConvert(Database.LeadConvert[] records)
Registers lead conversion requests to be executed during context commit.
Signature:
public forvendi.ModificationContext addToConvert(Database.LeadConvert record)
public forvendi.ModificationContext addToConvert(List<Database.LeadConvert> records)Parameters:
record/records: Single or list ofDatabase.LeadConvertinstances.
Return Value: forvendi.ModificationContext – Self-reference for method chaining.
addToSend(Messaging.SingleEmailMessage record) / addToSend(Messaging.SingleEmailMessage[] records)
Queues single email messages to be sent during context commit.
Signature:
public forvendi.ModificationContext addToSend(Messaging.SingleEmailMessage record)
public forvendi.ModificationContext addToSend(List<Messaging.SingleEmailMessage> records)Parameters:
record/records: Single or list ofMessaging.SingleEmailMessageinstances.
Return Value: forvendi.ModificationContext – Self-reference for method chaining.
addEventToPublish(SObject record) / addEventToPublish(SObject[] records)
Queues Platform Events for publication.
Signature:
public forvendi.ModificationContext addEventToPublish(SObject record)
public forvendi.ModificationContext addEventToPublish(List<SObject> records)Parameters:
record/records: Platform Event record or list of event records.
Return Value: forvendi.ModificationContext – Self-reference for method chaining.
Inspection & Query Methods
hasRecords(): Returnstrueif the context contains any pending modifications.hasRecordsToUpdate(Id recordId): Checks if a record with the specified ID is queued for updates.getRecordsToUpdate(Id recordId)/getRecordsToUpdate(SObject record): Retrieves the queued update instance for a given ID or record.clear(): Clears all queued modifications, deletes, events, and conversions.
Extraction Methods
getRecordsUpdate(): Returns queued update records grouped bySObjectType.getRecordsToRemove(): Returns queued delete records grouped bySObjectType.getRecordsToAsyncInsert(): Returns queued async insert records grouped bySObjectType.getRecordsToAsyncUpdate(): Returns queued async update records grouped bySObjectType.getRecordsToAsyncRemove(): Returns queued async delete records grouped bySObjectType.getRecordsToHardRemove(): Returns queued hard delete records grouped bySObjectType.getEventToPublish(): Returns queued Platform Events grouped bySObjectType.getAllRecordsToRemove(): Returns all soft-delete and hard-delete records combined.getRecordsToConvert(): Returns queuedDatabase.LeadConvertinstances mapped by Lead ID.getMessageToSend(): Returns queuedMessaging.SingleEmailMessageinstances.
save() Methods
Executes all accumulated DML, conversion, email sending, and event publishing operations within the context.
Signatures:
public forvendi.DB.DBResult save()
public forvendi.DB.DBResult save(Boolean allOrNone)
public forvendi.DB.DBResult save(forvendi.DB.DML dml, Boolean allOrNone)Parameters:
dml: Instance offorvendi.DB.DMLspecifying sharing security rules.allOrNone:truefor transactional strictness (throws exception on failure),falsefor partial success support.
Return Value: forvendi.DB.DBResult – Consolidated execution result containing status and error information.