ModificationContext

ModificationContext stores SObject records to insert, update or delete.


addToInsert(SObject record)

Adds the given record to the list of records to be inserted in the database..

Parameters:

  • record - the record to be inserted to the database.

Return:

.ModificationContext self-reference to chain invocations.


addToAsyncInsert(SObject record)

Adds a single SObject record to an asynchronous insert operation.

Parameters:

  • record - the record to be inserted to the database.

Return:

.ModificationContext self-reference to chain invocations.


addToAsyncInsert(SObject[] records)

Similar to previous but with possibility to adds one or more sObject records to the insert operations in this modification context.

Parameters:

  • record - the record to be asynchronosly inserted to the database.

addToUpdate(SObject record)

Adds the given record to the list of records to be updated in the database.

Parameters:

  • record - the record to be updated to the database.

Return:

.ModificationContext self-reference to chain invocations.


addToUpdate(SObject[] records)

Similar to previous but with possibility to adds one or more sObject records to the update operations in this modification contex


addToAsyncUpdate(SObject record)

Adds a single SObject record to an asynchronous update operation.

Parameters:

  • record - the record to be updated to the database.

Return:

.ModificationContext self-reference to chain invocations.


addToAsyncUpdate(SObject[] records)

Similar to previous but with possibility to adds one or more sObject records to the update operations in this modification context.


addModificationToUpdate(Id recordId, SObjectField objectField, Object value)

Adds a single field modification to an SObject record to be updated

Parameters:

  • recordId - the ID of the SObject record to be updated.
  • objectField - The field of the SObject to be modified
  • value - The value to set for the specified field

Return:

.ModificationContext self-reference to chain invocations.


addModificationToUpdate(Id recordId, String objectField, Object value)

Adds a single field modification to an SObject record to be updated

Parameters:

  • recordId - the ID of the SObject record to be updated.
  • objectField - The field of the SObject to be modified, specified as a string
  • value - The value to set for the specified field

Return:

.ModificationContext self-reference to chain invocations.


addModificationToUpdate(Id recordId, Map<SObjectField, Object> changes)

Adds a single field modification to an SObject record to be updated

Parameters:

  • recordId - the ID of the SObject record to be updated.
  • changes - A map of field-value pairs representing the modifications to be made to the SObject record

Return:

.ModificationContext self-reference to chain invocations.


addModificationToUpdate(SObject record, SObjectField objectField, Object value)

Adds a single field modification to an SObject record to be updated

Parameters:

  • record - the SObject record to be updated.
  • objectField - The field of the SObject to be modified
  • value - The value to set for the specified field

Return:

.ModificationContext self-reference to chain invocations.


addModificationToUpdate(SObject record, Map<SObjectField, Object> changes)

Adds a single field modification to an SObject record to be updated

Parameters:

  • record - the SObject record to be updated.
  • changes - A map of field-value pairs representing the modifications to be made to the SObject record

Return:

.ModificationContext self-reference to chain invocations.


addToRemove(SObject[] records)

Adds an array of SObject records to the map of records to be removed

Parameters:

  • records - the array of SObject records to be removed.

Return:

.ModificationContext self-reference to chain invocations.


addToRemove(SObject record)

Adds a single SObject record to the List of records to be removed

Parameters:

  • record - a single SObject record to be removed.

Return:

.ModificationContext self-reference to chain invocations.


addToAsyncRemove(SObject[] records)

Adds an array of SObject records to the map of records to be removed asynchronously

Parameters:

  • records - the array of SObject records to be removed.

Return:

.ModificationContext self-reference to chain invocations.


addToAsyncRemove(SObject record)

Adds a single SObject record to the List of records to be removed asynchronously

Parameters:

  • record - a single SObject record to be removed.

Return:

.ModificationContext self-reference to chain invocations.


addToHardRemove(SObject[] records)

Adds an array of SObject records to the map of records to be hard removed

Parameters:

  • records - the array of SObject records to be hard removed.

Return: .ModificationContext self-reference to chain invocations.


addToHardRemove(SObject record)

Adds a single SObject record to the List of records to be hard removed

Parameters: record - a single SObject record to be removed.

Return:

.ModificationContext self-reference to chain invocations.


addToConvert(Database.LeadConvert record)

Adds a LeadConvert record to the map of records to be converted

Parameters:

  • record - the LeadConvert record to add to the map of records to be converted

Return:

.ModificationContext self-reference to chain invocations.


addToConvert(Database.LeadConvert[] records)

Adds an array of LeadConvert records to the map of records to be converted

Parameters:

  • records - the array of LeadConvert records to be converted.

Return:

.ModificationContext self-reference to chain invocations.


addToSend(Messaging.SingleEmailMessage record)

Adds a SingleEmailMessage record to the list of messages to be sent

Parameters:

  • record - the SingleEmailMessage record to be sent

Return:

.ModificationContext self-reference to chain invocations.


addToSend(Messaging.SingleEmailMessage[] records)

Adds an array of singleEmailMessage records to the list of messages to be sent

Parameters:

  • records - the array of the SingleEmailMessage records to be sent

Return:

.ModificationContext self-reference to chain invocations.


addEventToPublish(SObject record)

Adds an SObject record to the platform event publication queue.

Parameters:

  • record - the SObject record to add to the platform event publication queue.

Return:

.ModificationContext self-reference to chain invocations.


addEventToPublish(SObject[] records)

Adds an array of SObject records to the platform event publication queue.

Parameters:

  • records - the array SObject records to add to the platform event publication queue.

Return:

.ModificationContext self-reference to chain invocations.


hasRecords()

Determines if modification context contains records to modify.

Return:

True if modification context contains any data, false otherwise.


hasRecordsToUpdate(Id recordId)

Determines if a record with selected id is in the modification scope.

Parameters:

  • recordId - The Id of the record to check for.

Return:

True if modification context contains record with specified id.


getRecordsToUpdate(Id recordId)

Retrieves the record to update with the given ID.

Parameters:

  • recordId - The Id of the record to retrieve.

Return:

The record to update with the given Id, or null if no such record exists in the records to update.


getRecordsToUpdate(SObject recordId)

Retrieves the updated version of the given record, if it exists in the records to update.

Parameters:

  • recordId - The record to retrieve the updated version of.

Return:

The updated version of the given record, or the input record if it does not exist in the records to update.


clear()

Clears all changes in the modification context.


getRecordsUpdate()

Gets all records to update.

Return:

Records to update split by SObject Types.


getRecordsToRemove()

Gets all records to delete.

Return:

Records to deletesplit by SObject Types.


getRecordsToAsyncInsert()

Gets all records to async insert.

Return:

Records to insert split by SObject Types.


getRecordsToAsyncUpdate()

Gets all records to async update.

Return:

Records to update split by SObject Types.


getRecordsToAsyncRemove()

Gets all records to async delete.

Return:

Records to delete split by SObject Types.


getRecordsToHardRemove()

Gets all records to hard delete.

Return:

Records to hard delete split by SObject Types.


getEventToPublish()

Gets all events which are waiting for publication.

Return:

Records to publish split by SObject Types.


getAllRecordsToRemove()

Gets all records to delete and hard remove.

Return:

Records to delete split by SObject Types.


getRecordsToConvert()

Gets all records to convert.

Return:

Database.LeadConvert records by Lead ids.


getMessageToSend()

Get messages to send.

Return:

Messaging.SingleEmailMessage records to send.


save()

Saves modification context.


save(Boolean allOrNone)

Saves modification context.

Parameters:

  • allOrNone - determines DML strategy:
    • true - all or none (throws exception),
    • false - partial success (returns DB.DBResult)

Return:

Db.DbResult instance that represents the result of the save operation


save(DB.DML dml, Boolean allOrNone)

Saves modification context.

Parameters:

  • Dml - determines record sharing strategy.
  • allOrNone - determines DML strategy:
    • true - all or none (throws exception),
    • false - partial success (returns DB.DBResult)

Return:

Db.DbResult instance that represents the result of the save operation