Database Class
Contains methods for creating and manipulating data.
Some Database methods also exist as DML statements.
By default, database operations run in user mode. To explicitly specify the access mode of database operation, set the accessLevel parameter.
See Also
The following are methods for Database. All methods are static.
-
convertLead(leadToConvert, accessLevel)
Converts a lead into an account and contact, and, optionally, an opportunity.
-
convertLead(leadsToConvert, accessLevel)
Converts a list of LeadConvert objects into accounts and contacts, and, optionally, opportunities.
-
convertLead(leadToConvert, allOrNone)
Converts a lead into an account and contact, as well as (optionally) an opportunity.
-
convertLead(leadsToConvert, allOrNone)
Converts a list of LeadConvert objects into accounts and contacts, as well as (optionally) opportunities.
-
convertLead(leadToConvert, dmlOptions)
Converts a lead into an account and contact, as well as (optionally) an opportunity.
-
convertLead(leadsToConvert, dmlOptions)
Converts a list of LeadConvert objects into accounts and contacts, as well as (optionally) opportunities.
-
convertLead(leadToConvert, allOrNone, accessLevel)
Converts a lead into an account and contact, as well as (optionally) an opportunity.
-
convertLead(leadsToConvert, allOrNone, accessLevel)
Converts a list of LeadConvert objects into accounts and contacts, as well as (optionally) opportunities.
-
convertLead(leadToConvert, dmlOptions, accessLevel)
Converts a lead into an account and contact, as well as (optionally) an opportunity.
-
convertLead(leadsToConvert, dmlOptions, accessLevel)
Converts a list of LeadConvert objects into accounts and contacts, as well as (optionally) opportunities.
-
Returns the number of records that a dynamic SOQL query would return when executed.
-
countQuery(query, accessLevel)
Returns the number of records that a dynamic SOQL query would return when executed.
-
countQueryWithBinds(query, bindMap, accessLevel)
Returns the number of records that a dynamic SOQL query would return when executed. Bind variables in the query are resolved from the bindMap Map parameter directly with the key, rather than from Apex code variables.
-
delete(recordToDelete, allOrNone)
Deletes an existing sObject record, such as an individual account or contact, from your organization’s data.
-
delete(recordsToDelete, allOrNone)
Deletes a list of existing sObject records, such as individual accounts or contacts, from your organization’s data.
-
Deletes existing sObject records, such as individual accounts or contacts, from your organization’s data.
-
Deletes a list of existing sObject records, such as individual accounts or contacts, from your organization’s data.
-
delete(recordToDelete, allOrNone, accessLevel)
Deletes an existing sObject record, such as an individual account or contact, from your organization’s data.
-
delete(recordsToDelete, allOrNone, accessLevel)
Deletes a list of existing sObject records, such as individual accounts or contacts, from your organization’s data.
-
delete(recordID, allOrNone, accessLevel)
Deletes existing sObject records, such as individual accounts or contacts, from your organization’s data.
-
delete(recordIDs, allOrNone, accessLevel)
Deletes a list of existing sObject records, such as individual accounts or contacts, from your organization’s data.
-
deleteAsync(sobjects, callback)
Initiates requests to delete the external data that corresponds to the specified external object records. The request is executed asynchronously, as a background operation, and is sent to the external system that’s defined by the external object’s associated external data source. Allows referencing a callback class whose
processDeletemethod is called for each record after deletion. -
deleteAsync(sobject, callback)
Initiates a request to delete the external data that corresponds to the specified external object record. The request is executed asynchronously, as a background operation, and is sent to the external system that’s defined by the external object’s associated external data source. Allows referencing a callback class whose
processDeletemethod is called after deletion. -
Initiates requests to delete the external data that corresponds to the specified external object records. The requests are executed asynchronously, as background operations, and are sent to the external systems that are defined by the external objects’ associated external data sources.
-
Initiates a request to delete the external data that corresponds to the specified external object record. The request is executed asynchronously, as a background operation, and is sent to the external system that’s defined by the external object’s associated external data source.
-
deleteAsync(sobjects, callback, accessLevel)
Initiates requests to delete the external data that corresponds to the specified external object records. The request is executed asynchronously, as a background operation, and is sent to the external system that’s defined by the external object’s associated external data source. Allows referencing a callback class whose
processDeletemethod is called for each record after deletion. -
deleteAsync(sobject, callback, accessLevel)
Initiates a request to delete the external data that corresponds to the specified external object record. The request is executed asynchronously, as a background operation, and is sent to the external system that’s defined by the external object’s associated external data source. Allows referencing a callback class whose
processDeletemethod is called after deletion. -
deleteAsync(sobjects, accessLevel)
Initiates requests to delete the external data that corresponds to the specified external object records. The requests are executed asynchronously, as background operations, and are sent to the external systems that are defined by the external objects’ associated external data sources.
-
deleteAsync(sobject, accessLevel)
Initiates a request to delete the external data that corresponds to the specified external object record. The request is executed asynchronously, as a background operation, and is sent to the external system that’s defined by the external object’s associated external data source.
-
Initiates requests to delete the external data that corresponds to the specified external object records. The requests are executed synchronously and are sent to the external systems that are defined by the external objects’ associated external data sources. If the Apex transaction contains pending changes, the synchronous operations can’t be completed and throw exceptions.
-
Initiates a request to delete the external data that corresponds to the specified external object record. The request is executed synchronously and is sent to the external system that’s defined by the external object’s associated external data source. If the Apex transaction contains pending changes, the synchronous operation can’t be completed and throws an exception.
-
deleteImmediate(sobjects, accessLevel)
Initiates requests to delete the external data that corresponds to the specified external object records. The requests are executed synchronously and are sent to the external systems that are defined by the external objects’ associated external data sources. If the Apex transaction contains pending changes, the synchronous operations can’t be completed and throw exceptions.
-
deleteImmediate(sobject, accessLevel)
Initiates a request to delete the external data that corresponds to the specified external object record. The request is executed synchronously and is sent to the external system that’s defined by the external object’s associated external data source. If the Apex transaction contains pending changes, the synchronous operation can’t be completed and throws an exception.
-
Permanently deletes the specified records from the Recycle Bin.
-
Permanently deletes the specified sObject from the Recycle Bin.
-
emptyRecycleBin(listOfSObjects)
Permanently deletes the specified sObjects from the Recycle Bin.
-
executeBatch(batchClassObject)
Submits a batch Apex job for execution corresponding to the specified class.
-
executeBatch(batchClassObject, scope)
Submits a batch Apex job for execution using the specified class and scope.
-
getAsyncDeleteResult(deleteResult)
Retrieves the status of an asynchronous delete operation that’s identified by a
Database.DeleteResultobject. -
getAsyncDeleteResult(asyncLocator)
Retrieves the result of an asynchronous delete operation based on the result’s unique identifier.
-
Returns the
asyncLocatorassociated with the result of a specified asynchronous insert, update, or delete operation. -
getAsyncSaveResult(saveResult)
Returns the status of an asynchronous insert or update operation that’s identified by a
Database.SaveResultobject. -
getAsyncSaveResult(asyncLocator)
Returns the status of an asynchronous insert or update operation based on the unique identifier associated with each modification.
-
Creates a cursor when the specified SOQL query is executed.
-
Creates a cursor when the specified SOQL query is executed.
-
getCursorWithBinds(query, bindMap, accessLevel)
Creates a cursor when the specified SOQL query is executed.
-
getDeleted(sObjectType, startDate, endDate)
Returns the list of individual records that have been deleted for an sObject type within the specified start and end dates and times and that are still in the Recycle Bin.
-
Creates a pagination cursor when the specified SOQL query is executed.
-
getPaginationCursor(query, accessLevel)
Creates a pagination cursor when the specified SOQL query is executed.
-
getPaginationCursorWithBinds(query, bindMap, accessLevel)
Creates a pagination cursor when the specified SOQL query is executed.
-
getQueryLocator(staticSoqlQueryResult)
Creates a QueryLocator object used in batch Apex or Visualforce.
-
Creates a QueryLocator object used in batch Apex or Visualforce.
-
getQueryLocator(staticSoqlQueryResult, accessLevel)
Creates a QueryLocator object used in batch Apex or Visualforce.
-
getQueryLocator(query, accessLevel)
Creates a QueryLocator object used in batch Apex or Visualforce.
-
getQueryLocatorWithBinds(query, bindMap, accessLevel)
Creates a QueryLocator object used in batch Apex or Visualforce. Bind variables in the query are resolved from the bindMap Map parameter directly with the key, rather than from Apex code variables.
-
getUpdated(sobjectType, startDate, endDate)
Returns the list of individual records that have been updated for an sObject type within the specified start and end dates and times.
-
insert(recordToInsert, allOrNone)
Adds an sObject, such as an individual account or contact, to your organization’s data.
-
insert(recordsToInsert, allOrNone)
Adds one or more sObjects, such as individual accounts or contacts, to your organization’s data.
-
insert(recordToInsert, dmlOptions)
Adds an sObject, such as an individual account or contact, to your organization’s data.
-
insert(recordsToInsert, dmlOptions)
Adds one or more sObjects, such as individual accounts or contacts, to your organization’s data.
-
insert(recordToInsert, allOrNone, accessLevel)
Adds an sObject, such as an individual account or contact, to your organization’s data.
-
insert(recordsToInsert, allOrNone, accessLevel)
Adds one or more sObjects, such as individual accounts or contacts, to your organization’s data.
-
insert(recordToInsert, dmlOptions, accessLevel)
Adds an sObject, such as an individual account or contact, to your organization’s data.
-
insert(recordsToInsert, dmlOptions, accessLevel)
Adds one or more sObjects, such as individual accounts or contacts, to your organization’s data.
-
insertAsync(sobjects, callback)
Initiates requests to add external object data to the relevant external systems. The requests are executed asynchronously, as background operations, and are sent to the external systems that are defined by the external objects’ associated external data sources. Allows referencing a callback class whose
processSavemethod is called for each record after the remote operations are completed. -
insertAsync(sobject, callback)
Initiates a request to add external object data to the relevant external system. The request is executed asynchronously, as a background operation, and is sent to the external system that’s defined by the external object’s associated external data source. Allows referencing a callback class whose
processSavemethod is called after the remote operation is completed. -
Initiates requests to add external object data to the relevant external systems. The requests are executed asynchronously, as background operations, and are sent to the external systems that are defined by the external objects’ associated external data sources.
-
Initiates a request to add external object data to the relevant external system. The request is executed asynchronously, as a background operation, and is sent to the external system that’s defined by the external object’s associated external data source.
-
insertAsync(sobjects, callback, accessLevel)
Initiates requests to add external object data to the relevant external systems. The requests are executed asynchronously, as background operations, and are sent to the external systems that are defined by the external objects’ associated external data sources. Allows referencing a callback class whose
processSavemethod is called for each record after the remote operations are completed. -
insertAsync(sobject, callback, accessLevel)
Initiates a request to add external object data to the relevant external system. The request is executed asynchronously, as a background operation, and is sent to the external system that’s defined by the external object’s associated external data source. Allows referencing a callback class whose
processSavemethod is called after the remote operation is completed. -
insertAsync(sobjects, accessLevel)
Initiates requests to add external object data to the relevant external systems. The requests are executed asynchronously, as background operations, and are sent to the external systems that are defined by the external objects’ associated external data sources.
-
insertAsync(sobject, accessLevel)
Initiates a request to add external object data to the relevant external system. The request is executed asynchronously, as a background operation, and is sent to the external system that’s defined by the external object’s associated external data source.
-
Initiates requests to add external object data to the relevant external systems. The requests are executed synchronously and are sent to the external systems that are defined by the external objects’ associated external data sources. If the Apex transaction contains pending changes, the synchronous operations can’t be completed and throw exceptions.
-
Initiates a request to add external object data to the relevant external system. The request is executed synchronously and is sent to the external system that’s defined by the external object’s associated external data source. If the Apex transaction contains pending changes, the synchronous operation can’t be completed and throws an exception.
-
insertImmediate(sobjects, accessLevel)
Initiates requests to add external object data to the relevant external systems. The requests are executed synchronously and are sent to the external systems that are defined by the external objects’ associated external data sources. If the Apex transaction contains pending changes, the synchronous operations can’t be completed and throw exceptions.
-
insertImmediate(sobject, accessLevel)
Initiates a request to add external object data to the relevant external system. The request is executed synchronously and is sent to the external system that’s defined by the external object’s associated external data source. If the Apex transaction contains pending changes, the synchronous operation can’t be completed and throws an exception.
-
merge(mergeToRecord, duplicateId)
Merges the duplicate record into the
mergeToRecordsObject record of the same type, deleting the duplicate, and reparenting any related records. Merges only accounts, contacts, or leads. -
merge(mergeToRecord, duplicateRecord)
Merges the duplicate sObject record into the
mergeToRecordsObject record of the same type, deleting the duplicate, and reparenting any related records. -
merge(mergeToRecord, duplicateIds)
Merges up to two records of the same sObject type into the
mergeToRecordsObject record, deleting the others, and reparenting any related records. -
merge(mergeToRecord, duplicateRecords)
Merges up to two records of the same object type into the
mergeToRecordsObject record, deleting the others, and reparenting any related records. -
merge(mergeToRecord, duplicateId, allOrNone)
Merges the duplicate record into the
mergeToRecordsObject record of the same type, optionally returning any errors, deleting the duplicate, and reparenting any related records. Merges only accounts, contacts, or leads. -
merge(mergeToRecord, duplicateRecord, allOrNone)
Merges the duplicate sObject record into the
mergeToRecordsObject of the same type, optionally returning any errors, deleting the duplicate, and reparenting any related records. -
merge(mergeToRecord, duplicateIds, allOrNone)
Merges up to two records of the same sObject type into the
mergeToRecordsObject record, optionally returning any errors, deleting the duplicates, and reparenting any related records. -
merge(mergeToRecord, duplicateRecords, allOrNone)
Merges up to two records of the same object type into the
mergeToRecordsObject record, optionally returning any errors, deleting the duplicates, and reparenting any related records. -
merge(mergeToRecord, duplicateId, accessLevel)
Merges the duplicate record into the
mergeToRecordsObject record of the same type, deleting the duplicate, and reparenting any related records. Merges only accounts, contacts, or leads. -
merge(mergeToRecord, duplicateRecord, accessLevel)
Merges the specified duplicate sObject record into the
mergeToRecordsObject of the same type, deleting the duplicate, and reparenting any related records. -
merge(mergeToRecord, duplicateIds, accessLevel)
Merges up to two records of the same sObject type into the
mergeToRecordsObject record, deleting the others, and reparenting any related records. -
merge(mergeToRecord, duplicateRecords, accessLevel)
Merges up to two records of the same object type into the
mergeToRecordsObject record, deleting the others, and reparenting any related records. -
merge(mergeToRecord, duplicateId, allOrNone, accessLevel)
Merges the duplicate record into the
mergeToRecordsObject record of the same type, optionally returning any errors, deleting the duplicate, and reparenting any related records. Merges only accounts, contacts, or leads. -
merge(mergeToRecord, duplicateRecord, allOrNone, accessLevel)
Merges the duplicate sObject record into the
mergeToRecordsObject record of the same type, optionally returning any errors, deleting the duplicate, and reparenting any related records. -
merge(mergeToRecord, duplicateIds, allOrNone, accessLevel)
Merges up to two records of the same sObject type into the
mergeToRecordsObject record, optionally returning any errors, deleting the duplicates, and reparenting any related records. -
merge(mergeToRecord, duplicateRecords, allOrNone, accessLevel)
Merges up to two records of the same object type into the
mergeToRecordsObject record, optionally returning any errors, deleting the duplicates, and reparenting any related records. -
Creates a dynamic SOQL query at runtime.
-
query(queryString, accessLevel)
Creates a dynamic SOQL query at runtime.
-
queryWithBinds(queryString, bindMap, accessLevel)
Creates a dynamic SOQL query at runtime. Bind variables in the query are resolved from the bindMap Map parameter directly with the key, rather than from Apex code variables.
-
releaseSavepoint(databaseSavepoint)
Releases a given savepoint. All savepoints that are subsequent to the given one are also released.
-
Restores the database to the state specified by the savepoint variable. Any emails submitted since the last savepoint are also rolled back and not sent.
-
Returns a savepoint variable that can be stored as a local variable, then used with the
rollbackmethod to restore the database to that point. -
undelete(recordToUndelete, allOrNone)
Restores an existing sObject record, such as an individual account or contact, from your organization’s Recycle Bin.
-
undelete(recordsToUndelete, allOrNone)
Restores one or more existing sObject records, such as individual accounts or contacts, from your organization’s Recycle Bin.
-
Restores an existing sObject record, such as an individual account or contact, from your organization’s Recycle Bin.
-
undelete(recordIDs, allOrNone)
Restores one or more existing sObject records, such as individual accounts or contacts, from your organization’s Recycle Bin.
-
undelete(recordToUndelete, allOrNone, accessLevel)
Restores an existing sObject record, such as an individual account or contact, from your organization’s Recycle Bin.
-
undelete(recordsToUndelete, allOrNone, accessLevel)
Restores one or more existing sObject records, such as individual accounts or contacts, from your organization’s Recycle Bin.
-
undelete(recordID, allOrNone, accessLevel)
Restores an existing sObject record, such as an individual account or contact, from your organization’s Recycle Bin.
-
undelete(recordIDs, allOrNone, accessLevel)
Restores one or more existing sObject records, such as individual accounts or contacts, from your organization’s Recycle Bin.
-
update(recordToUpdate, allOrNone)
Modifies an existing sObject record, such as an individual account or contact, in your organization’s data.
-
update(recordsToUpdate, allOrNone)
Modifies one or more existing sObject records, such as individual accounts or contacts, in your organization’s data.
-
update(recordToUpdate, dmlOptions)
Modifies an existing sObject record, such as an individual account or contact, in your organization’s data.
-
update(recordsToUpdate, dmlOptions)
Modifies one or more existing sObject records, such as individual accounts or contacts, in your organization’s data.
-
update(recordToUpdate, allOrNone, accessLevel)
Modifies an existing sObject record, such as an individual account or contact, in your organization’s data.
-
update(recordsToUpdate, allOrNone, accessLevel)
Modifies one or more existing sObject records, such as individual accounts or contacts, in your organization’s data.
-
update(recordToUpdate, dmlOptions, accessLevel)
Modifies an existing sObject record, such as an individual account or contact, in your organization’s data.
-
update(recordsToUpdate, dmlOptions, accessLevel)
Modifies one or more existing sObject records, such as individual accounts or contacts, in your organization’s data.
-
upsert(recordToUpsert, externalIdField, allOrNone)
Creates a new sObject record or updates an existing sObject record within a single statement, using a specified field to determine the presence of existing objects, or the ID field if no field is specified.
-
upsert(recordsToUpsert, externalIdField, allOrNone)
Creates new sObject records or updates existing sObject records within a single statement, using a specified field to determine the presence of existing objects, or the ID field if no field is specified.
-
upsert(recordToUpsert, externalIdField, allOrNone, accessLevel)
Creates a new sObject record or updates an existing sObject record within a single statement, using a specified field to determine the presence of existing objects, or the ID field if no field is specified.
-
upsert(recordsToUpsert, externalIdField, allOrNone, accessLevel)
Creates new sObject records or updates existing sObject records within a single statement, using a specified field to determine the presence of existing objects, or the ID field if no field is specified.
-
updateAsync(sobjects, callback)
Initiates requests to update external object data on the relevant external systems. The requests are executed asynchronously, as background operations, and are sent to the external systems that are defined by the external objects’ associated external data sources. Allows referencing a callback class whose
processSavemethod is called for each record after the remote operations are completed. -
updateAsync(sobject, callback)
Initiates a request to update external object data on the relevant external system. The request is executed asynchronously, as a background operation, and is sent to the external system that’s defined by the external object’s associated external data source. Allows referencing a callback class whose
processSavemethod is called after the remote operation is completed. -
Initiates requests to update external object data on the relevant external systems. The requests are executed asynchronously, as background operations, and are sent to the external systems that are defined by the external objects’ associated external data sources.
-
Initiates a request to update external object data on the relevant external system. The request is executed asynchronously, as a background operation, and is sent to the external system that’s defined by the external object’s associated external data source.
-
updateAsync(sobjects, callback, accessLevel)
Initiates requests to update external object data on the relevant external systems. The requests are executed asynchronously, as background operations, and are sent to the external systems that are defined by the external objects’ associated external data sources. Allows referencing a callback class whose
processSavemethod is called for each record after the remote operations are completed. -
updateAsync(sobject, callback, accessLevel)
Initiates a request to update external object data on the relevant external system. The request is executed asynchronously, as a background operation, and is sent to the external system that’s defined by the external object’s associated external data source. Allows referencing a callback class whose
processSavemethod is called after the remote operation is completed. -
updateAsync(sobjects, accessLevel)
Initiates requests to update external object data on the relevant external systems. The requests are executed asynchronously, as background operations, and are sent to the external systems that are defined by the external objects’ associated external data sources.
-
updateAsync(sobject, accessLevel)
Initiates a request to update external object data on the relevant external system. The request is executed asynchronously, as a background operation, and is sent to the external system that’s defined by the external object’s associated external data source.
-
Initiates requests to update external object data on the relevant external systems. The requests are executed synchronously and are sent to the external systems that are defined by the external objects’ associated external data sources. If the Apex transaction contains pending changes, the synchronous operations can’t be completed and throw exceptions.
-
Initiates a request to update external object data on the relevant external system. The request is executed synchronously and is sent to the external system that’s defined by the external object’s associated external data source. If the Apex transaction contains pending changes, the synchronous operation can’t be completed and throws an exception.
-
updateImmediate(sobjects, accessLevel)
Initiates requests to update external object data on the relevant external systems. The requests are executed synchronously and are sent to the external systems that are defined by the external objects’ associated external data sources. If the Apex transaction contains pending changes, the synchronous operations can’t be completed and throw exceptions.
-
updateImmediate(sobject, accessLevel)
Initiates a request to update external object data on the relevant external system. The request is executed synchronously and is sent to the external system that’s defined by the external object’s associated external data source. If the Apex transaction contains pending changes, the synchronous operation can’t be completed and throws an exception.
Converts a lead into an account and contact, and, optionally, an opportunity.
public static Database.LeadConvertResult convertLead(Database.LeadConvert leadToConvert, System.AccessLevel accessLevel)
-
leadToConvert:
Type: Database.LeadConvert
-
accessLevel:
Type: System.AccessLevel
(Optional) The accessLevel parameter specifies whether the method runs in system mode (
AccessLevel.SYSTEM_MODE) or user mode (AccessLevel.USER_MODE). In system mode, the object and field-level permissions of the current user are ignored, and the record sharing rules are controlled by the class sharing keywords. In user mode, the object permissions, field-level security, and sharing rules of the current user are enforced. User mode is the default.
Type: Database.LeadConvertResult
We recommend passing a maximum of 100 LeadConvert objects to the convertLead method. Including more than 100 objects per call can result in Apex governor limit errors.
Each executed convertLead method counts against the governor limit for DML statements.
Converts a list of LeadConvert objects into accounts and contacts, and, optionally, opportunities.
public static List<Database.LeadConvertResult> convertLead(List<Database.LeadConvert> leadConverts, System.AccessLevel accessLevel)
-
leadsToConvert:
Type: List<Database.LeadConvert>
-
accessLevel:
Type: System.AccessLevel
(Optional) The accessLevel parameter specifies whether the method runs in system mode (
AccessLevel.SYSTEM_MODE) or user mode (AccessLevel.USER_MODE). In system mode, the object and field-level permissions of the current user are ignored, and the record sharing rules are controlled by the class sharing keywords. In user mode, the object permissions, field-level security, and sharing rules of the current user are enforced. User mode is the default.
Type: List<Database.LeadConvertResult>
We recommend passing a maximum of 100 LeadConvert objects to the convertLead method. Including more than 100 objects per call can result in Apex governor limit errors.
Each executed convertLead method counts against the governor limit for DML statements.
Converts a lead into an account and contact, as well as (optionally) an opportunity.
public static Database.LeadConvertResult convertLead(Database.LeadConvert leadToConvert, Boolean allOrNone)
-
leadToConvert:
Type: Database.LeadConvert
-
allOrNone:
Type: Boolean
Type: Database.LeadConvertResult
We recommend passing a maximum of 100 LeadConvert objects to the convertLead method. Including more than 100 objects per call can result in Apex governor limit errors.
Each executed convertLead method counts against the governor limit for DML statements.
Converts a list of LeadConvert objects into accounts and contacts, as well as (optionally) opportunities.
public static Database.LeadConvertResult[] convertLead(Database.LeadConvert[] leadsToConvert, Boolean allOrNone)
-
leadsToConvert:
Type: Database.LeadConvert[]
-
allOrNone:
Type: Boolean
Type: Database.LeadConvertResult[]
We recommend passing a maximum of 100 LeadConvert objects to the convertLead method. Including more than 100 objects per call can result in Apex governor limit errors.
Each executed convertLead method counts against the governor limit for DML statements.
Converts a lead into an account and contact, as well as (optionally) an opportunity.
public static Database.LeadConvertResult convertLead(Database.LeadConvert leadToConvert, Database.DMLOptions dmlOptions)
-
leadToConvert:
Type: Database.LeadConvert
-
dmlOptions:
Type: Database.DMLOptions
The optional dmlOptions parameter specifies additional data for the transaction, such as assignment rule information or rollback behavior when errors occur during record insertions.
Type: Database.LeadConvertResult
We recommend passing a maximum of 100 LeadConvert objects to the convertLead method. Including more than 100 objects per call can result in Apex governor limit errors.
Each executed convertLead method counts against the governor limit for DML statements.
Converts a list of LeadConvert objects into accounts and contacts, as well as (optionally) opportunities.
public static List<Database.LeadConvertResult> convertLead(List<Database.LeadConvert> leadsToConvert, Database.DMLOptions dmlOptions)
-
leadsToConvert:
Type: List<Database.LeadConvert>
-
dmlOptions:
Type: Database.DMLOptions
The optional dmlOptions parameter specifies additional data for the transaction, such as assignment rule information or rollback behavior when errors occur during record insertions.
Type: List<Database.LeadConvertResult>
We recommend passing a maximum of 100 LeadConvert objects to the convertLead method. Including more than 100 objects per call can result in Apex governor limit errors.
Each executed convertLead method counts against the governor limit for DML statements.
Converts a lead into an account and contact, as well as (optionally) an opportunity.
public static Database.LeadConvertResult convertLead(Database.LeadConvert leadToConvert, Boolean allOrNone, System.AccessLevel accessLevel)
-
leadToConvert:
Type: Database.LeadConvert
-
allOrNone:
Type: Boolean
-
accessLevel:
Type: System.AccessLevel
(Optional) The accessLevel parameter specifies whether the method runs in system mode (
AccessLevel.SYSTEM_MODE) or user mode (AccessLevel.USER_MODE). In system mode, the object and field-level permissions of the current user are ignored, and the record sharing rules are controlled by the class sharing keywords. In user mode, the object permissions, field-level security, and sharing rules of the current user are enforced. User mode is the default.
Type: Database.LeadConvertResult
We recommend passing a maximum of 100 LeadConvert objects to the convertLead method. Including more than 100 objects per call can result in Apex governor limit errors.
Each executed convertLead method counts against the governor limit for DML statements.
Converts a list of LeadConvert objects into accounts and contacts, as well as (optionally) opportunities.
public static List<Database.LeadConvertResult> convertLead(List<Database.LeadConvert> leadsToConvert, Boolean allOrNone, System.AccessLevel accessLevel)
-
leadsToConvert:
Type: List<Database.LeadConvert>
-
allOrNone:
Type: Boolean
-
accessLevel:
Type: System.AccessLevel
(Optional) The accessLevel parameter specifies whether the method runs in system mode (
AccessLevel.SYSTEM_MODE) or user mode (AccessLevel.USER_MODE). In system mode, the object and field-level permissions of the current user are ignored, and the record sharing rules are controlled by the class sharing keywords. In user mode, the object permissions, field-level security, and sharing rules of the current user are enforced. User mode is the default.
Type: List<Database.LeadConvertResult>
We recommend passing a maximum of 100 LeadConvert objects to the convertLead method. Including more than 100 objects per call can result in Apex governor limit errors.
Each executed convertLead method counts against the governor limit for DML statements.
Converts a lead into an account and contact, as well as (optionally) an opportunity.
public static Database.LeadConvertResult convertLead(Database.LeadConvert leadToConvert, Database.DMLOptions dmlOptions, System.AccessLevel accessLevel)
-
leadToConvert:
Type: Database.LeadConvert
-
dmlOptions:
Type: Database.DMLOptions
The optional dmlOptions parameter specifies additional data for the transaction, such as assignment rule information or rollback behavior when errors occur during record insertions.
-
accessLevel:
Type: System.AccessLevel
(Optional) The accessLevel parameter specifies whether the method runs in system mode (
AccessLevel.SYSTEM_MODE) or user mode (AccessLevel.USER_MODE). In system mode, the object and field-level permissions of the current user are ignored, and the record sharing rules are controlled by the class sharing keywords. In user mode, the object permissions, field-level security, and sharing rules of the current user are enforced. User mode is the default.
Type: Database.LeadConvertResult
We recommend passing a maximum of 100 LeadConvert objects to the convertLead method. Including more than 100 objects per call can result in Apex governor limit errors.
Each executed convertLead method counts against the governor limit for DML statements.
Converts a list of LeadConvert objects into accounts and contacts, as well as (optionally) opportunities.
public static List<Database.LeadConvertResult> convertLead(List<Database.LeadConvert> leadsToConvert, Database.DMLOptions dmlOptions, System.AccessLevel accessLevel)
-
leadsToConvert:
Type: List<Database.LeadConvert>
-
dmlOptions:
Type: Database.DMLOptions
The optional dmlOptions parameter specifies additional data for the transaction, such as assignment rule information or rollback behavior when errors occur during record insertions.
-
accessLevel:
Type: System.AccessLevel
(Optional) The accessLevel parameter specifies whether the method runs in system mode (
AccessLevel.SYSTEM_MODE) or user mode (AccessLevel.USER_MODE). In system mode, the object and field-level permissions of the current user are ignored, and the record sharing rules are controlled by the class sharing keywords. In user mode, the object permissions, field-level security, and sharing rules of the current user are enforced. User mode is the default.
Type: List<Database.LeadConvertResult>
We recommend passing a maximum of 100 LeadConvert objects to the convertLead method. Including more than 100 objects per call can result in Apex governor limit errors.
Each executed convertLead method counts against the governor limit for DML statements.
Returns the number of records that a dynamic SOQL query would return when executed.
public static Integer countQuery(String query)
-
query:
Type: String
Type: Integer
For more information, see Dynamic SOQL.
Each executed countQuery method counts against the governor limit for SOQL queries.
Returns the number of records that a dynamic SOQL query would return when executed.
public static Integer countQuery(String query, System.AccessLevel accessLevel)
-
query:
Type: String
-
accessLevel:
Type: System.AccessLevel
(Optional) The accessLevel parameter specifies whether the method runs in system mode (
AccessLevel.SYSTEM_MODE) or user mode (AccessLevel.USER_MODE). In system mode, the object and field-level permissions of the current user are ignored, and the record sharing rules are controlled by the class sharing keywords. In user mode, the object permissions, field-level security, and sharing rules of the current user are enforced. User mode is the default.
Type: Integer
For more information, see Dynamic SOQL.
Each executed countQuery method counts against the governor limit for SOQL queries.
Returns the number of records that a dynamic SOQL query would return when executed. Bind variables in the query are resolved from the bindMap Map parameter directly with the key, rather than from Apex code variables.
public static Integer countQueryWithBinds(String query, Map<String, Object> bindMap, System.AccessLevel accessLevel)
-
query:
Type: String
SOQL query that includes Apex bind variables preceded by a colon. All bind variables must have a key in the bindMap Map.
-
bindMap:
Type: Map<String, Object> A map that contains keys for each bind variable specified in the SOQL queryString and its value. The keys can’t be null or duplicates, and the values can’t be null or empty strings.
-
accessLevel:
Type: System.AccessLevel
The accessLevel parameter specifies whether the method runs in system mode (
AccessLevel.SYSTEM_MODE) or user mode (AccessLevel.USER_MODE). In system mode, the object and field-level permissions of the current user are ignored, and the record sharing rules are controlled by the class sharing keywords. In user mode, the object permissions, field-level security, and sharing rules of the current user are enforced.
Type: Integer
For more information, see Dynamic SOQL.
Each executed countQueryWithBinds method counts against the governor limit for SOQL queries.
In this example, the SOQL query uses a bind variable for an Account name. Its value (Acme Inc.) is passed in to the method using the nameBind Map. The accountName variable isn’t (and doesn’t have to be) in scope when the query is executed within the method.
Deletes an existing sObject record, such as an individual account or contact, from your organization’s data.
public static Database.DeleteResult delete(SObject recordToDelete, Boolean allOrNone)
Type: Database.DeleteResult
delete is analogous to the delete() statement in the SOAP API.
Each executed delete method counts against the governor limit for DML statements.
Deletes a list of existing sObject records, such as individual accounts or contacts, from your organization’s data.
public static Database.DeleteResult[] delete(SObject[] recordsToDelete, Boolean allOrNone)
Type: Database.DeleteResult[]
delete is analogous to the delete() statement in the SOAP API.
Each executed delete method counts against the governor limit for DML statements.
The following example deletes an account named ‘DotCom’:
Deletes existing sObject records, such as individual accounts or contacts, from your organization’s data.
public static Database.DeleteResult delete(ID recordID, Boolean allOrNone)
Type: Database.DeleteResult
delete is analogous to the delete() statement in the SOAP API.
Each executed delete method counts against the governor limit for DML statements.
To delete a share object record for a custom object, you must pass an sObject instead of a recordID. The recordID parameter isn’t supported for share objects for custom objects.
Deletes a list of existing sObject records, such as individual accounts or contacts, from your organization’s data.
public static Database.DeleteResult[] delete(ID[] recordIDs, Boolean allOrNone)
Type: Database.DeleteResult[]
delete is analogous to the delete() statement in the SOAP API.
Each executed delete method counts against the governor limit for DML statements.
To delete a share object record for a custom object, you must pass an sObject instead of a recordID. The recordID parameter isn’t supported for share objects for custom objects.
Deletes an existing sObject record, such as an individual account or contact, from your organization’s data.
public static Database.DeleteResult delete(SObject recordToDelete, Boolean allOrNone, System.AccessLevel accessLevel)
-
recordToDelete:
Type: sObject
-
allOrNone:
Type: Boolean
-
accessLevel:
Type: System.AccessLevel
(Optional) The accessLevel parameter specifies whether the method runs in system mode (
AccessLevel.SYSTEM_MODE) or user mode (AccessLevel.USER_MODE). In system mode, the object and field-level permissions of the current user are ignored, and the record sharing rules are controlled by the class sharing keywords. In user mode, the object permissions, field-level security, and sharing rules of the current user are enforced. User mode is the default.
Type: Database.DeleteResult
delete is analogous to the delete() statement in the SOAP API.
Each executed delete method counts against the governor limit for DML statements.
Deletes a list of existing sObject records, such as individual accounts or contacts, from your organization’s data.
public static List<Database.DeleteResult> delete(List<SObject> recordsToDelete, Boolean allOrNone, System.AccessLevel accessLevel)
-
recordsToDelete:
Type: List<sObject>
-
allOrNone:
Type: Boolean
-
accessLevel:
Type: System.AccessLevel
(Optional) The accessLevel parameter specifies whether the method runs in system mode (
AccessLevel.SYSTEM_MODE) or user mode (AccessLevel.USER_MODE). In system mode, the object and field-level permissions of the current user are ignored, and the record sharing rules are controlled by the class sharing keywords. In user mode, the object permissions, field-level security, and sharing rules of the current user are enforced. User mode is the default.
Type: List<Database.DeleteResult>
delete is analogous to the delete() statement in the SOAP API.
Each executed delete method counts against the governor limit for DML statements.
Deletes existing sObject records, such as individual accounts or contacts, from your organization’s data.
public static Database.DeleteResult delete(Id recordID, Boolean allOrNone, System.AccessLevel accessLevel)
-
recordID:
Type: ID
-
allOrNone:
Type: Boolean
-
accessLevel:
Type: System.AccessLevel
(Optional) The accessLevel parameter specifies whether the method runs in system mode (
AccessLevel.SYSTEM_MODE) or user mode (AccessLevel.USER_MODE). In system mode, the object and field-level permissions of the current user are ignored, and the record sharing rules are controlled by the class sharing keywords. In user mode, the object permissions, field-level security, and sharing rules of the current user are enforced. User mode is the default.
Type: Database.DeleteResult
delete is analogous to the delete() statement in the SOAP API.
Each executed delete method counts against the governor limit for DML statements.
To delete a share object record for a custom object, you must pass an sObject instead of a recordID. The recordID parameter isn’t supported for share objects for custom objects.
Deletes a list of existing sObject records, such as individual accounts or contacts, from your organization’s data.
public static List<Database.DeleteResult> delete(List<Id> recordIDs, Boolean allOrNone, System.AccessLevel accessLevel)
-
recordIDs:
Type: List<ID>
-
allOrNone:
Type: Boolean
-
accessLevel:
Type: System.AccessLevel
(Optional) The accessLevel parameter specifies whether the method runs in system mode (
AccessLevel.SYSTEM_MODE) or user mode (AccessLevel.USER_MODE). In system mode, the object and field-level permissions of the current user are ignored, and the record sharing rules are controlled by the class sharing keywords. In user mode, the object permissions, field-level security, and sharing rules of the current user are enforced. User mode is the default.
Type: List<Database.DeleteResult>
delete is analogous to the delete() statement in the SOAP API.
Each executed delete method counts against the governor limit for DML statements.
To delete a share object record for a custom object, you must pass an sObject instead of a recordID. The recordID parameter isn’t supported for share objects for custom objects.
Initiates requests to delete the external data that corresponds to the specified external object records. The request is executed asynchronously, as a background operation, and is sent to the external system that’s defined by the external object’s associated external data source. Allows referencing a callback class whose processDelete method is called for each record after deletion.
public static List<Database.DeleteResult> deleteAsync(List<SObject> sobjects, DataSource.AsyncDeleteCallback callback)
-
sobjects:
Type: List<SObject>
List of external object records to delete.
-
callback:
Type: DataSource.AsyncDeleteCallback
The callback that contains the state in the originating context and an action (the
processDeletemethod) that is executed after the insert operation is completed. Use the action callback to update org data according to the operation’s results. The callback object must extendDataSource.AsyncDeleteCallback.
Type: List<Database.DeleteResult>
Status results for the delete operation. Each result corresponds to a record processed by this asynchronous operation and is associated with a unique identifier (asyncLocator). The asyncLocator value is included in the errors array of the result. You can retrieve this identifier with Database.getAsyncLocator(). Retrieve the final result with Database.getAsyncDeleteResult().
Initiates a request to delete the external data that corresponds to the specified external object record. The request is executed asynchronously, as a background operation, and is sent to the external system that’s defined by the external object’s associated external data source. Allows referencing a callback class whose processDelete method is called after deletion.
public static Database.DeleteResult deleteAsync(SObject sobject, DataSource.AsyncDeleteCallback callback)
-
sobject:
Type: SObject The external object record to delete.
-
callback:
Type: DataSource.AsyncDeleteCallback
The callback that contains the state in the originating context and an action (the
processDeletemethod) that is executed after the insert operation is completed. Use the action callback to update org data according to the operation’s results. The callback object must extendDataSource.AsyncDeleteCallback.
Type: Database.DeleteResult
Status result for the delete operation. The result corresponds to the record processed by this asynchronous operation and is associated with a unique identifier (asyncLocator). The asyncLocator value is included in the errors array of the result. You can retrieve this identifier with Database.getAsyncLocator(). Retrieve the final result with Database.getAsyncDeleteResult().
Initiates requests to delete the external data that corresponds to the specified external object records. The requests are executed asynchronously, as background operations, and are sent to the external systems that are defined by the external objects’ associated external data sources.
public static List<Database.DeleteResult> deleteAsync(List<SObject> sobjects)
-
sobjects:
Type: List<SObject>
List of external object records to delete.
Type: List<Database.DeleteResult>
Status results for the delete operation. Each result corresponds to a record processed by this asynchronous operation and is associated with a unique identifier (asyncLocator). The asyncLocator value is included in the errors array of the result. You can retrieve this identifier with Database.getAsyncLocator(). Retrieve the final result with Database.getAsyncDeleteResult().
Initiates a request to delete the external data that corresponds to the specified external object record. The request is executed asynchronously, as a background operation, and is sent to the external system that’s defined by the external object’s associated external data source.
public static Database.DeleteResult deleteAsync(SObject sobject)
-
sobject:
Type: SObject
The external object record to delete.
Type: Database.DeleteResult
Status result for the delete operation. The result corresponds to the record processed by this asynchronous operation and is associated with a unique identifier (asyncLocator). The asyncLocator value is included in the errors array of the result. You can retrieve this identifier with Database.getAsyncLocator(). Retrieve the final result with Database.getAsyncDeleteResult().
Initiates requests to delete the external data that corresponds to the specified external object records. The request is executed asynchronously, as a background operation, and is sent to the external system that’s defined by the external object’s associated external data source. Allows referencing a callback class whose processDelete method is called for each record after deletion.
public static List<Database.DeleteResult> deleteAsync(List<SObject> sobjects, DataSource.AsyncDeleteCallback callback, System.AccessLevel accessLevel)
-
sobjects:
Type: List<SObject>
List of external object records to delete.
-
callback:
Type: DataSource.AsyncDeleteCallback
The callback that contains the state in the originating context and an action (the
processDeletemethod) that is executed after the insert operation is completed. The execution is in system mode regardless of theaccessLevelparameter. Use the action callback to update org data according to the operation’s results. The callback object must extendDataSource.AsyncDeleteCallback. -
accessLevel:
Type: System.AccessLevel
(Optional) The accessLevel parameter specifies whether the method runs in system mode (
AccessLevel.SYSTEM_MODE) or user mode (AccessLevel.USER_MODE). In system mode, the object and field-level permissions of the current user are ignored, and the record sharing rules are controlled by the class sharing keywords. In user mode, the object permissions, field-level security, and sharing rules of the current user are enforced. User mode is the default.
Type: List<Database.DeleteResult>
Status results for the delete operation. Each result corresponds to a record processed by this asynchronous operation and is associated with a unique identifier (asyncLocator). The asyncLocator value is included in the errors array of the result. You can retrieve this identifier with Database.getAsyncLocator(). Retrieve the final result with Database.getAsyncDeleteResult().
Initiates a request to delete the external data that corresponds to the specified external object record. The request is executed asynchronously, as a background operation, and is sent to the external system that’s defined by the external object’s associated external data source. Allows referencing a callback class whose processDelete method is called after deletion.
public static Database.DeleteResult deleteAsync(SObject sobject, DataSource.AsyncDeleteCallback callback, System.AccessLevel accessLevel)
-
sobject:
Type: SObject The external object record to delete.
-
callback:
Type: DataSource.AsyncDeleteCallback
The callback that contains the state in the originating context and an action (the
processDeletemethod) that is executed after the insert operation is completed. The execution is in system mode regardless of theaccessLevelparameter. Use the action callback to update org data according to the operation’s results. The callback object must extendDataSource.AsyncDeleteCallback. -
accessLevel:
Type: System.AccessLevel
(Optional) The accessLevel parameter specifies whether the method runs in system mode (
AccessLevel.SYSTEM_MODE) or user mode (AccessLevel.USER_MODE). In system mode, the object and field-level permissions of the current user are ignored, and the record sharing rules are controlled by the class sharing keywords. In user mode, the object permissions, field-level security, and sharing rules of the current user are enforced. User mode is the default.
Type: Database.DeleteResult
Status result for the delete operation. The result corresponds to the record processed by this asynchronous operation and is associated with a unique identifier (asyncLocator). The asyncLocator value is included in the errors array of the result. You can retrieve this identifier with Database.getAsyncLocator(). Retrieve the final result with Database.getAsyncDeleteResult().
Initiates requests to delete the external data that corresponds to the specified external object records. The requests are executed asynchronously, as background operations, and are sent to the external systems that are defined by the external objects’ associated external data sources.
public static List<Database.DeleteResult> deleteAsync(List<SObject> sobjects, System.AccessLevel accessLevel)
-
sobjects:
Type: List<SObject>
List of external object records to delete.
-
accessLevel:
Type: System.AccessLevel
(Optional) The accessLevel parameter specifies whether the method runs in system mode (
AccessLevel.SYSTEM_MODE) or user mode (AccessLevel.USER_MODE). In system mode, the object and field-level permissions of the current user are ignored, and the record sharing rules are controlled by the class sharing keywords. In user mode, the object permissions, field-level security, and sharing rules of the current user are enforced. User mode is the default.
Type: List<Database.DeleteResult>
Status results for the delete operation. Each result corresponds to a record processed by this asynchronous operation and is associated with a unique identifier (asyncLocator). The asyncLocator value is included in the errors array of the result. You can retrieve this identifier with Database.getAsyncLocator(). Retrieve the final result with Database.getAsyncDeleteResult().
Initiates a request to delete the external data that corresponds to the specified external object record. The request is executed asynchronously, as a background operation, and is sent to the external system that’s defined by the external object’s associated external data source.
public static Database.DeleteResult deleteAsync(SObject sobject, System.AccessLevel accessLevel)
-
sobject:
Type: SObject
The external object record to delete.
-
accessLevel:
Type: System.AccessLevel
(Optional) The accessLevel parameter specifies whether the method runs in system mode (
AccessLevel.SYSTEM_MODE) or user mode (AccessLevel.USER_MODE). In system mode, the object and field-level permissions of the current user are ignored, and the record sharing rules are controlled by the class sharing keywords. In user mode, the object permissions, field-level security, and sharing rules of the current user are enforced. User mode is the default.
Type: Database.DeleteResult
Status result for the delete operation. The result corresponds to the record processed by this asynchronous operation and is associated with a unique identifier (asyncLocator). The asyncLocator value is included in the errors array of the result. You can retrieve this identifier with Database.getAsyncLocator(). Retrieve the final result with Database.getAsyncDeleteResult().
Initiates requests to delete the external data that corresponds to the specified external object records. The requests are executed synchronously and are sent to the external systems that are defined by the external objects’ associated external data sources. If the Apex transaction contains pending changes, the synchronous operations can’t be completed and throw exceptions.
public static List<Database.DeleteResult> deleteImmediate(List<SObject> sobjects)
-
sobjects:
Type: List<SObject>
List of external object records to delete.
Type: List<Database.DeleteResult>
Status results for the delete operation.
The batch limit for big objects using deleteImmediate() is 50,000 records at once.
Initiates a request to delete the external data that corresponds to the specified external object record. The request is executed synchronously and is sent to the external system that’s defined by the external object’s associated external data source. If the Apex transaction contains pending changes, the synchronous operation can’t be completed and throws an exception.
public static Database.DeleteResult deleteImmediate(SObject sobject)
-
sobject:
Type: SObject
The external object record to delete.
Type: Database.DeleteResult
Status result for the delete operation.
Initiates requests to delete the external data that corresponds to the specified external object records. The requests are executed synchronously and are sent to the external systems that are defined by the external objects’ associated external data sources. If the Apex transaction contains pending changes, the synchronous operations can’t be completed and throw exceptions.
public static List<Database.DeleteResult> deleteImmediate(List<SObject> sobjects, System.AccessLevel accessLevel)
-
sobjects:
Type: List<SObject>
List of external object records to delete.
-
accessLevel:
Type: System.AccessLevel
(Optional) The accessLevel parameter specifies whether the method runs in system mode (
AccessLevel.SYSTEM_MODE) or user mode (AccessLevel.USER_MODE). In system mode, the object and field-level permissions of the current user are ignored, and the record sharing rules are controlled by the class sharing keywords. In user mode, the object permissions, field-level security, and sharing rules of the current user are enforced. User mode is the default.
Type: List<Database.DeleteResult>
Status results for the delete operation.
The batch limit for big objects using deleteImmediate() is 50,000 records at once.
Initiates a request to delete the external data that corresponds to the specified external object record. The request is executed synchronously and is sent to the external system that’s defined by the external object’s associated external data source. If the Apex transaction contains pending changes, the synchronous operation can’t be completed and throws an exception.
public static Database.DeleteResult deleteImmediate(SObject sobject, System.AccessLevel accessLevel)
-
sobject:
Type: SObject
The external object record to delete.
-
accessLevel:
Type: System.AccessLevel
(Optional) The accessLevel parameter specifies whether the method runs in system mode (
AccessLevel.SYSTEM_MODE) or user mode (AccessLevel.USER_MODE). In system mode, the object and field-level permissions of the current user are ignored, and the record sharing rules are controlled by the class sharing keywords. In user mode, the object permissions, field-level security, and sharing rules of the current user are enforced. User mode is the default.
Type: Database.DeleteResult
Status result for the delete operation.
Permanently deletes the specified records from the Recycle Bin.
public static Database.EmptyRecycleBinResult[] emptyRecycleBin(ID [] recordIds)
-
recordIds:
Type: ID[]
Type: Database.EmptyRecycleBinResult[]
Note the following:
- After records are deleted using this method, they cannot be undeleted.
- Only 10,000 records can be specified for deletion.
- Logged in users can delete any record that they can query in their Recycle Bin, or the recycle bins of any subordinates. If logged in users have “Modify All Data” permission, they can query and delete records from any Recycle Bin in the organization.
- Cascade delete record IDs should not be included in the list of IDs; otherwise an error occurs. For example, if an account record is deleted, all related contacts, opportunities, contracts, and so on are also deleted. Only include the Id of the top-level account. All related records are automatically removed.
- Deleted items are added to the number of items processed by a DML statement, and the method call is added to the total number of DML statements issued. Each executed
emptyRecycleBinmethod counts against the governor limit for DML statements.
Permanently deletes the specified sObject from the Recycle Bin.
public static Database.EmptyRecycleBinResult emptyRecycleBin(sObject obj)
-
obj:
Type: sObject
Type: Database.EmptyRecycleBinResult
Note the following:
- After an sObject is deleted using this method, it cannot be undeleted.
- Only 10,000 sObjects can be specified for deletion.
- The logged-in user can delete any sObject (that can be queried) in their Recycle Bin, or the recycle bins of any subordinates. If the logged-in user has “Modify All Data” permission, they can query and delete sObjects from any Recycle Bin in the organization.
- Do not include an sObject that was deleted due to a cascade delete; otherwise an error occurs. For example, if an account is deleted, all related contacts, opportunities, contracts, and so on are also deleted. Only include sObjects of the top-level account. All related sObjects are automatically removed.
Permanently deletes the specified sObjects from the Recycle Bin.
public static Database.EmptyRecycleBinResult[] emptyRecycleBin(sObject[] listOfSObjects)
-
listOfSObjects:
Type: sObject[]
Type: Database.EmptyRecycleBinResult[]
Note the following:
- After an sObject is deleted using this method, it cannot be undeleted.
- Only 10,000 sObjects can be specified for deletion.
- The logged-in user can delete any sObject (that can be queried) in their Recycle Bin, or the recycle bins of any subordinates. If the logged-in user has “Modify All Data” permission, they can query and delete sObjects from any Recycle Bin in the organization.
- Do not include an sObject that was deleted due to a cascade delete; otherwise an error occurs. For example, if an account is deleted, all related contacts, opportunities, contracts, and so on are also deleted. Only include sObjects of the top-level account. All related sObjects are automatically removed.
Submits a batch Apex job for execution corresponding to the specified class.
public static ID executeBatch(Object batchClassObject)
-
batchClassObject:
Type:
Object An instance of a class that implements the Database.Batchable interface.
Type: ID
The ID of the new batch job (AsyncApexJob).
When calling this method, Salesforce chunks the records returned by the start method of the batch class into batches of 200, and then passes each batch to the execute method. Apex governor limits are reset for each execution of execute.
For more information, see Using Batch Apex.
If the executeBatch call fails to acquire an Apex flex queue lock:
- In API version 52.0 and later, the call throws a
System.AsyncException. - In API version 51.0 and earlier, the call returns an empty ID, “000000000000000”, instead of throwing an exception.
Submits a batch Apex job for execution using the specified class and scope.
public static ID executeBatch(Object batchClassObject, Integer scope)
-
batchClassObject:
Type:
Object An instance of a class that implements the Database.Batchable interface.
-
scope:
Type: Integer
Number of records to be passed into
the
executemethod for batch processing.
Type: ID
The ID of the new batch job (AsyncApexJob).
The value for scope must be greater than 0.
If the start method of the batch class returns a Database.QueryLocator, the scope parameter of Database.executeBatch can have a maximum value of 2,000. If set to a higher value, Salesforce chunks the records returned by the QueryLocator into smaller batches of up to 200 records. If the start method of the batch class returns an iterable, the scope parameter value has no upper limit; however, if you use a very high number, you could run into other limits.
Apex governor limits are reset for each execution of execute.
For more information, see Using Batch Apex.
If the executeBatch call fails to acquire an Apex flex queue lock:
- In API version 52.0 and later, the call throws a
System.AsyncException. - In API version 51.0 and earlier, the call returns an empty ID, “000000000000000”, instead of throwing an exception.
Retrieves the status of an asynchronous delete operation that’s identified by a Database.DeleteResult object.
public static Database.DeleteResult getAsyncDeleteResult(Database.DeleteResult deleteResult)
-
deleteResult:
Type: Database.DeleteResult
The result record for the delete operation being retrieved.
Type: Database.DeleteResult
The result of a completed asynchronous delete of a record or records.
Retrieves the result of an asynchronous delete operation based on the result’s unique identifier.
public static Database.DeleteResult getAsyncDeleteResult(String asyncLocator)
-
asyncLocator:
Type: String
The unique identifier associated with the result of an asynchronous operation.
Type: Database.DeleteResult
The result of a completed asynchronous delete of a record or records.
Returns the asyncLocator associated with the result of a specified asynchronous insert, update, or delete operation.
public static String getAsyncLocator(Object result)
-
result:
Type: Object
The saved result of an asynchronous insert, update, or delete operation. The result object can be of type
Database.SaveResultorDatabase.DeleteResult.
Type: String
The unique identifier associated with the result of the specified operation.
Returns the status of an asynchronous insert or update operation that’s identified by a Database.SaveResult object.
public static Database.SaveResult getAsyncSaveResult(Database.SaveResult saveResult)
-
saveResult:
Type: Database.SaveResult
The result record for the insert or update operation being retrieved.
The result of a completed asynchronous operation on a record or records.
Returns the status of an asynchronous insert or update operation based on the unique identifier associated with each modification.
public static Database.SaveResult getAsyncSaveResult(String asyncLocator)
-
asyncLocator:
Type: String The unique identifier associated with the result of an asynchronous operation.
The result of a completed asynchronous operation on a record or records.
Creates a cursor when the specified SOQL query is executed.
public static Database.Cursor getCursor(String query)
-
query:
Type: String
The SOQL query to be run.
Type: Database.Cursor
Creates a cursor when the specified SOQL query is executed.
public static Database.Cursor getCursor(String query, Object accessLevel)
-
query:
Type: String
The SOQL query to be run.
-
accessLevel:
Type: System.AccessLevel
(Optional) The accessLevel parameter specifies whether the method runs in system mode (
AccessLevel.SYSTEM_MODE) or user mode (AccessLevel.USER_MODE). In system mode, the object and field-level permissions of the current user are ignored, and the record sharing rules are controlled by the class sharing keywords. In user mode, the object permissions, field-level security, and sharing rules of the current user are enforced. User mode is the default.
Type: Database.Cursor
Creates a cursor when the specified SOQL query is executed.
public static Database.Cursor getCursorWithBinds(String query, Map bindMap, Object accessLevel)
-
query:
Type: String
The SOQL query to be run.
-
bindMap:
Type: Map
A map that contains placeholder keys for each bind variable specified in the SOQL query string and its value.
-
accessLevel:
Type: System.AccessLevel
(Optional) The accessLevel parameter specifies whether the method runs in system mode (
AccessLevel.SYSTEM_MODE) or user mode (AccessLevel.USER_MODE). In system mode, the object and field-level permissions of the current user are ignored, and the record sharing rules are controlled by the class sharing keywords. In user mode, the object permissions, field-level security, and sharing rules of the current user are enforced. User mode is the default.
Type: Database.Cursor
Returns the list of individual records that have been deleted for an sObject type within the specified start and end dates and times and that are still in the Recycle Bin.
public static Database.GetDeletedResult getDeleted(String sObjectType, Datetime startDate, Datetime endDate)
-
sObjectType:
Type: String
The sObjectType argument is the sObject type name for which to get the deleted records, such as account or merchandise__c.
-
startDate:
Type: Datetime
Start date and time of the deleted records time window.
-
endDate:
Type: Datetime
End date and time of the deleted records time window.
Type: Database.GetDeletedResult
Because the Recycle Bin holds records up to 15 days, results are returned for no more than 15 days previous to the day the call is executed (or earlier if an administrator has purged the Recycle Bin).
Creates a pagination cursor when the specified SOQL query is executed.
public static Database.PaginationCursor getPaginationCursor(String query)
-
query:
Type: String
The SOQL query to be run.
Type: Database.PaginationCursor
Creates a pagination cursor when the specified SOQL query is executed.
public static Database.PaginationCursor getPaginationCursor(String query, Object accessLevel)
-
query:
Type: String
The SOQL query to be run.
-
accessLevel:
Type: System.AccessLevel
(Optional) The accessLevel parameter specifies whether the method runs in system mode (
AccessLevel.SYSTEM_MODE) or user mode (AccessLevel.USER_MODE). In system mode, the object and field-level permissions of the current user are ignored, and the record sharing rules are controlled by the class sharing keywords. In user mode, the object permissions, field-level security, and sharing rules of the current user are enforced. User mode is the default.
Type: Database.PaginationCursor
Creates a pagination cursor when the specified SOQL query is executed.
public static Database.PaginationCursor getPaginationCursorWithBinds(String query, Map bindMap, Object accessLevel)
-
query:
Type: String
The SOQL query to be run.
-
bindMap:
Type: Map
A map that contains placeholder keys for each bind variable specified in the SOQL query string and its value.
-
accessLevel:
Type: System.AccessLevel
(Optional) The accessLevel parameter specifies whether the method runs in system mode (
AccessLevel.SYSTEM_MODE) or user mode (AccessLevel.USER_MODE). In system mode, the object and field-level permissions of the current user are ignored, and the record sharing rules are controlled by the class sharing keywords. In user mode, the object permissions, field-level security, and sharing rules of the current user are enforced. User mode is the default.
Type: Database.PaginationCursor
Creates a QueryLocator object used in batch Apex or Visualforce.
public static Database. QueryLocator getQueryLocator(sObject [] staticSoqlQueryResult)
-
staticSoqlQueryResult:
Type: sObject []
The staticSoqlQueryResult parameter must be a static, inline SOQL query.
Type: Database.QueryLocator
You can’t use getQueryLocator with any query that contains an aggregate function.
Each executed getQueryLocator method counts against the governor limit of 10,000 total records retrieved and the total number of SOQL queries issued.
For more information, see Understanding Apex Managed Sharing, and IdeaStandardSetController Class.
Creates a QueryLocator object used in batch Apex or Visualforce.
public static Database.QueryLocator getQueryLocator(String query)
-
query:
Type: String
Type: Database.QueryLocator
You can’t use getQueryLocator with any query that contains an aggregate function.
Each executed getQueryLocator method counts against the governor limit of 10,000 total records retrieved and the total number of SOQL queries issued.
For more information, see Understanding Apex Managed Sharing, and StandardSetController Class.
Creates a QueryLocator object used in batch Apex or Visualforce.
public static Database.QueryLocator getQueryLocator(sObject [] staticSoqlQueryResult, System.AccessLevel accessLevel)
-
staticSoqlQueryResult:
Type: sObject []
The staticSoqlQueryResult parameter must be a static, inline SOQL query.
-
accessLevel:
Type: System.AccessLevel
(Optional) The accessLevel parameter specifies whether the method runs in system mode (
AccessLevel.SYSTEM_MODE) or user mode (AccessLevel.USER_MODE). In system mode, the object and field-level permissions of the current user are ignored, and the record sharing rules are controlled by the class sharing keywords. In user mode, the object permissions, field-level security, and sharing rules of the current user are enforced. User mode is the default.
Type: Database.QueryLocator
The access level is evaluated only when the QueryLocator is created. A QueryLocator can be long lived, such as when used in a batch. We don’t reevaluate the object and field-level security with each iteration of the QueryLocator. As a result, if you specify user mode, and then change the security settings after the QueryLocator is created, the new settings aren’t enforced.
You can’t use getQueryLocator with any query that contains an aggregate function.
Each executed getQueryLocator method counts against the governor limit of 10,000 total records retrieved and the total number of SOQL queries issued.
For more information, see Understanding Apex Managed Sharing, and IdeaStandardSetController Class.
Creates a QueryLocator object used in batch Apex or Visualforce.
public static Database.QueryLocator getQueryLocator(String query, System.AccessLevel accessLevel)
-
query:
Type: String
-
accessLevel:
Type: System.AccessLevel
(Optional) The accessLevel parameter specifies whether the method runs in system mode (
AccessLevel.SYSTEM_MODE) or user mode (AccessLevel.USER_MODE). In system mode, the object and field-level permissions of the current user are ignored, and the record sharing rules are controlled by the class sharing keywords. In user mode, the object permissions, field-level security, and sharing rules of the current user are enforced. User mode is the default.
Type: Database.QueryLocator
The access level is evaluated only when the QueryLocator is created. A QueryLocator can be long lived, such as when used in a batch. We don’t reevaluate the object and field-level security with each iteration of the QueryLocator. As a result, if you specify user mode, and then change the security settings after the QueryLocator is created, the new settings aren’t enforced.
You can’t use getQueryLocator with any query that contains an aggregate function.
Each executed getQueryLocator method counts against the governor limit of 10,000 total records retrieved and the total number of SOQL queries issued.
For more information, see Understanding Apex Managed Sharing, and StandardSetController Class.
Creates a QueryLocator object used in batch Apex or Visualforce. Bind variables in the query are resolved from the bindMap Map parameter directly with the key, rather than from Apex code variables.
public static Database.QueryLocator getQueryLocatorWithBinds(String query, Map<String, Object> bindMap, System.AccessLevel accessLevel)
- query
Type: String
SOQL query that includes Apex bind variables preceded by a colon. All bind variables must have a key in the bindMap Map.
- bindMap
A map that contains keys for each bind variable specified in the SOQL queryString and its value. The keys can’t be null or duplicates, and the values can’t be null or empty strings.
- accessLevel
Type: System.AccessLevel
The accessLevel parameter specifies whether the method runs in system mode (
AccessLevel.SYSTEM_MODE) or user mode (AccessLevel.USER_MODE). In system mode, the object and field-level permissions of the current user are ignored, and the record sharing rules are controlled by the class sharing keywords. In user mode, the object permissions, field-level security, and sharing rules of the current user are enforced.
Type: Database.QueryLocator
The access level is evaluated only when the QueryLocator is created. A QueryLocator can be long lived, such as when used in a batch. We don’t reevaluate the object and field-level security with each iteration of the QueryLocator. As a result, if you specify user mode, and then change the security settings after the QueryLocator is created, the new settings aren’t enforced.
You can’t use getQueryLocatorWithBinds with any query that contains an aggregate function.
Each executed getQueryLocatorWithBinds method counts against the governor limit for the total number of records retrieved by Database.getQueryLocator(10,000) and the total number of SOQL queries issued. See Per Transaction Apex Limits.
For more information, see Understanding Apex Managed Sharing, and StandardSetController Class.
In this example, the SOQL query uses a bind variable for an Account name. Its value (Acme Corporation) is passed in using the acctBinds Map.
Returns the list of individual records that have been updated for an sObject type within the specified start and end dates and times.
public static Database.GetUpdatedResult getUpdated(String sobjectType, Datetime startDate, Datetime endDate)
-
sobjectType:
Type: String
The sObjectType argument is the sObject type name for which to get the updated records, such as account or merchandise__c.
-
startDate:
Type: Datetime
The startDate argument is the start date and time of the updated records time window.
-
endDate:
Type: Datetime
The endDate argument is the end date and time of the updated records time window.
Type: Database.GetUpdatedResult
The date range for the returned results is no more than 30 days previous to the day the call is executed.
Adds an sObject, such as an individual account or contact, to your organization’s data.
public static Database.SaveResult insert(sObject recordToInsert, Boolean allOrNone)
Type: Database.SaveResult
insert is analogous to the INSERT statement in SQL.
Apex classes and triggers saved (compiled) using API version 15.0 and higher produce a runtime error if you assign a String value that is too long for the field.
Each executed insert method counts against the governor limit for DML statements.
Adds one or more sObjects, such as individual accounts or contacts, to your organization’s data.
public static Database.SaveResult[] insert(sObject[] recordsToInsert, Boolean allOrNone)
Type: Database.SaveResult[]
insert is analogous to the INSERT statement in SQL.
Apex classes and triggers saved (compiled) using API version 15.0 and higher produce a runtime error if you assign a String value that is too long for the field.
Each executed insert method counts against the governor limit for DML statements.
Example:
The following example inserts two accounts:
Adds an sObject, such as an individual account or contact, to your organization’s data.
public static Database.SaveResult insert(sObject recordToInsert, Database.DMLOptions dmlOptions)
-
recordToInsert:
Type: sObject
-
dmlOptions:
Type: Database.DMLOptions
The optional dmlOptions parameter specifies additional data for the transaction, such as assignment rule information or rollback behavior when errors occur during record insertions.
Type: Database.SaveResult
insert is analogous to the INSERT statement in SQL.
Apex classes and triggers saved (compiled) using API version 15.0 and higher produce a runtime error if you assign a String value that is too long for the field.
Each executed insert method counts against the governor limit for DML statements.
Adds one or more sObjects, such as individual accounts or contacts, to your organization’s data.
public static Database.SaveResult insert(sObject[] recordsToInsert, Database.DMLOptions dmlOptions)
-
recordsToInsert:
Type: sObject[]
-
dmlOptions:
Type: Database.DMLOptions
The optional dmlOptions parameter specifies additional data for the transaction, such as assignment rule information or rollback behavior when errors occur during record insertions.
Type: Database.SaveResult[]
insert is analogous to the INSERT statement in SQL.
Apex classes and triggers saved (compiled) using API version 15.0 and higher produce a runtime error if you assign a String value that is too long for the field.
Each executed insert method counts against the governor limit for DML statements.
Adds an sObject, such as an individual account or contact, to your organization’s data.
public static Database.SaveResult insert(SObject recordToInsert, Boolean allOrNone, System.AccessLevel accessLevel)
-
recordToInsert:
Type: sObject
-
allOrNone:
Type: Boolean
-
accessLevel:
Type: System.AccessLevel
(Optional) The accessLevel parameter specifies whether the method runs in system mode (
AccessLevel.SYSTEM_MODE) or user mode (AccessLevel.USER_MODE). In system mode, the object and field-level permissions of the current user are ignored, and the record sharing rules are controlled by the class sharing keywords. In user mode, the object permissions, field-level security, and sharing rules of the current user are enforced. User mode is the default.
Type: Database.SaveResult
If you use the accessLevel parameter to specify that the method runs in user mode, we report all encountered inaccessible fields. The way to retrieve the names of these inaccessible fields depends on the value of this method’s allOrNone parameter, or the equivalent DmlOptions.optAllOrNone property. If you specify that:
allOrNone=trueorDmlOptions.optAllOrNone=true: Catch theDMLExceptionand use theDMLException.getDMLFieldNames()method to retrieve the list of inaccessible fields. See Exception Class and Built-In Exceptions for more information.allOrNone=falseorDmlOptions.optAllOrNone=false: For each failing record, we update theDatabase.Errorobject that results from the DML operation. Use theError.getFields()method to retrieve the list of inaccessible fields. See the Error Class methods for more information.
insert is analogous to the INSERT statement in SQL.
Apex classes and triggers saved (compiled) using API version 15.0 and higher produce a runtime error if you assign a String value that is too long for the field.
Each executed insert method counts against the governor limit for DML statements.
Adds one or more sObjects, such as individual accounts or contacts, to your organization’s data.
public static List<Database.SaveResult> insert(List<SObject> recordsToInsert, Boolean allOrNone, System.AccessLevel accessLevel)
-
recordsToInsert:
Type: List<sObject>
-
allOrNone:
Type: Boolean
-
accessLevel:
Type: System.AccessLevel
(Optional) The accessLevel parameter specifies whether the method runs in system mode (
AccessLevel.SYSTEM_MODE) or user mode (AccessLevel.USER_MODE). In system mode, the object and field-level permissions of the current user are ignored, and the record sharing rules are controlled by the class sharing keywords. In user mode, the object permissions, field-level security, and sharing rules of the current user are enforced. User mode is the default.
Type: List<Database.SaveResult>
If you use the accessLevel parameter to specify that the method runs in user mode, we report all encountered inaccessible fields. The way to retrieve the names of these inaccessible fields depends on the value of this method’s allOrNone parameter, or the equivalent DmlOptions.optAllOrNone property. If you specify that:
allOrNone=trueorDmlOptions.optAllOrNone=true: Catch theDMLExceptionand use theDMLException.getDMLFieldNames()method to retrieve the list of inaccessible fields. See Exception Class and Built-In Exceptions for more information.allOrNone=falseorDmlOptions.optAllOrNone=false: For each failing record, we update theDatabase.Errorobject that results from the DML operation. Use theError.getFields()method to retrieve the list of inaccessible fields. See the Error Class methods for more information.
insert is analogous to the INSERT statement in SQL.
Apex classes and triggers saved (compiled) using API version 15.0 and higher produce a runtime error if you assign a String value that is too long for the field.
Each executed insert method counts against the governor limit for DML statements.
Adds an sObject, such as an individual account or contact, to your organization’s data.
public static Database.SaveResult insert(SObject recordToInsert, Database.DMLOptions dmlOptions, System.AccessLevel accessLevel)
-
recordToInsert:
Type: sObject
-
dmlOptions:
Type: Database.DMLOptions
The optional dmlOptions parameter specifies additional data for the transaction, such as assignment rule information or rollback behavior when errors occur during record insertions.
-
accessLevel:
Type: System.AccessLevel
(Optional) The accessLevel parameter specifies whether the method runs in system mode (
AccessLevel.SYSTEM_MODE) or user mode (AccessLevel.USER_MODE). In system mode, the object and field-level permissions of the current user are ignored, and the record sharing rules are controlled by the class sharing keywords. In user mode, the object permissions, field-level security, and sharing rules of the current user are enforced. User mode is the default.
Type: Database.SaveResult
insert is analogous to the INSERT statement in SQL.
Apex classes and triggers saved (compiled) using API version 15.0 and higher produce a runtime error if you assign a String value that is too long for the field.
Each executed insert method counts against the governor limit for DML statements.
Adds one or more sObjects, such as individual accounts or contacts, to your organization’s data.
public static List<Database.SaveResult> insert(List<SObject> recordsToInsert, Database.DMLOptions dmlOptions, System.AccessLevel accessLevel)
-
recordsToInsert:
Type: List<sObject>
-
dmlOptions:
Type: Database.DMLOptions
The optional dmlOptions parameter specifies additional data for the transaction, such as assignment rule information or rollback behavior when errors occur during record insertions.
-
accessLevel:
Type: System.AccessLevel
(Optional) The accessLevel parameter specifies whether the method runs in system mode (
AccessLevel.SYSTEM_MODE) or user mode (AccessLevel.USER_MODE). In system mode, the object and field-level permissions of the current user are ignored, and the record sharing rules are controlled by the class sharing keywords. In user mode, the object permissions, field-level security, and sharing rules of the current user are enforced. User mode is the default.
Type: List<Database.SaveResult>
insert is analogous to the INSERT statement in SQL.
Apex classes and triggers saved (compiled) using API version 15.0 and higher produce a runtime error if you assign a String value that is too long for the field.
Each executed insert method counts against the governor limit for DML statements.
Initiates requests to add external object data to the relevant external systems. The requests are executed asynchronously, as background operations, and are sent to the external systems that are defined by the external objects’ associated external data sources. Allows referencing a callback class whose processSave method is called for each record after the remote operations are completed.
public static List<Database.SaveResult> insertAsync(List<SObject> sobjects, DataSource.AsyncSaveCallback callback)
-
sobjects:
Type: List<SObject>
List of external object records to insert.
-
callback:
Type: DataSource.AsyncSaveCallback
The callback object that contains the state in the originating context and an action (the
processSavemethod) that executes after the insert operation is completed. Use the action callback to update org data according to the operation’s results. The callback object must extendDataSource.AsyncSaveCallback.
Type: List<Database.SaveResult>
Status results for the insert operation. Each result corresponds to a record processed by this asynchronous operation and is associated with a unique identifier (asyncLocator). The asyncLocator value is included in the errors array of the result. You can retrieve this identifier with Database.getAsyncLocator(). Retrieve the final result with Database.getAsyncSaveResult().
Database.insertAsync() methods can’t be executed in the context of a portal user, even when the portal user is a community member. To add external object records via Apex, use Database.insertImmediate() methods.
Initiates a request to add external object data to the relevant external system. The request is executed asynchronously, as a background operation, and is sent to the external system that’s defined by the external object’s associated external data source. Allows referencing a callback class whose processSave method is called after the remote operation is completed.
public static Database.SaveResult insertAsync(SObject sobject, DataSource.AsyncSaveCallback callback)
-
sobject:
Type: SObject The external object record to insert.
-
callback:
Type: DataSource.AsyncSaveCallback
The callback object that contains the state in the originating context and an action (the
processSavemethod) that executes after the insert operation is completed. Use the action callback to update org data according to the operation’s results. The callback object must extendDataSource.AsyncSaveCallback.
Type: Database.SaveResult
Status result for the insert operation. The result corresponds to the record processed by this asynchronous operation and is associated with a unique identifier (asyncLocator). The asyncLocator value is included in the errors array of the result. You can retrieve this identifier with Database.getAsyncLocator(). Retrieve the final result with Database.getAsyncSaveResult().
Database.insertAsync() methods can’t be executed in the context of a portal user, even when the portal user is a community member. To add external object records via Apex, use Database.insertImmediate() methods.
Initiates requests to add external object data to the relevant external systems. The requests are executed asynchronously, as background operations, and are sent to the external systems that are defined by the external objects’ associated external data sources.
public static List<Database.SaveResult> insertAsync(List<SObject> sobjects)
-
sobjects:
Type: List<SObject>
List of external object records to insert.
Type: List<Database.SaveResult>
Status results for the insert operation. Each result corresponds to a record processed by this asynchronous operation and is associated with a unique identifier (asyncLocator). The asyncLocator value is included in the errors array of the result. You can retrieve this identifier with Database.getAsyncLocator(). Retrieve the final result with Database.getAsyncSaveResult().
Database.insertAsync() methods can’t be executed in the context of a portal user, even when the portal user is a community member. To add external object records via Apex, use Database.insertImmediate() methods.
Initiates a request to add external object data to the relevant external system. The request is executed asynchronously, as a background operation, and is sent to the external system that’s defined by the external object’s associated external data source.
public static Database.SaveResult insertAsync(SObject sobject)
-
sobject:
Type: SObject
The external object record to insert.
Type: Database.SaveResult
Status result for the insert operation. The result corresponds to the record processed by this asynchronous operation and is associated with a unique identifier (asyncLocator). The asyncLocator value is included in the errors array of the result. You can retrieve this identifier with Database.getAsyncLocator(). Retrieve the final result with Database.getAsyncSaveResult().
Database.insertAsync() methods can’t be executed in the context of a portal user, even when the portal user is a community member. To add external object records via Apex, use Database.insertImmediate() methods.
Initiates requests to add external object data to the relevant external systems. The requests are executed asynchronously, as background operations, and are sent to the external systems that are defined by the external objects’ associated external data sources. Allows referencing a callback class whose processSave method is called for each record after the remote operations are completed.
public static List<Database.SaveResult> insertAsync(List<SObject> sobjects, DataSource.AsyncSaveCallback callback, System.AccessLevel accessLevel)
- sobjects: Type: List<SObject> List of external object records to insert.
- callback: Type: DataSource.AsyncSaveCallback The callback object that contains the state in the originating context and an action (the
processSavemethod) that executes after the insert operation is completed. The execution is in system mode regardless of theaccessLevelparameter. Use the action callback to update org data according to the operation’s results. The callback object must extendDataSource.AsyncSaveCallback. - accessLevel: Type: System.AccessLevel (Optional) The accessLevel parameter specifies whether the method runs in system mode (
AccessLevel.SYSTEM_MODE) or user mode (AccessLevel.USER_MODE). In system mode, the object and field-level permissions of the current user are ignored, and the record sharing rules are controlled by the class sharing keywords. In user mode, the object permissions, field-level security, and sharing rules of the current user are enforced. User mode is the default.
Type: List<Database.SaveResult>
Status results for the insert operation. Each result corresponds to a record processed by this asynchronous operation and is associated with a unique identifier (asyncLocator). The asyncLocator value is included in the errors array of the result. You can retrieve this identifier with Database.getAsyncLocator(). Retrieve the final result with Database.getAsyncSaveResult().
Database.insertAsync() methods can’t be executed in the context of a portal user, even when the portal user is a community member. To add external object records via Apex, use Database.insertImmediate() methods.
Initiates a request to add external object data to the relevant external system. The request is executed asynchronously, as a background operation, and is sent to the external system that’s defined by the external object’s associated external data source. Allows referencing a callback class whose processSave method is called after the remote operation is completed.
public static Database.SaveResult insertAsync(SObject sobject, DataSource.AsyncSaveCallback callback, System.AccessLevel accessLevel)
-
sobject:
Type: SObject The external object record to insert.
-
callback:
Type: DataSource.AsyncSaveCallback
The callback object that contains the state in the originating context and an action (the
processSavemethod) that executes after the insert operation is completed. The execution is in system mode regardless of theaccessLevelparameter. Use the action callback to update org data according to the operation’s results. The callback object must extendDataSource.AsyncSaveCallback. -
accessLevel:
Type: System.AccessLevel
(Optional) The accessLevel parameter specifies whether the method runs in system mode (
AccessLevel.SYSTEM_MODE) or user mode (AccessLevel.USER_MODE). In system mode, the object and field-level permissions of the current user are ignored, and the record sharing rules are controlled by the class sharing keywords. In user mode, the object permissions, field-level security, and sharing rules of the current user are enforced. User mode is the default.
Type: Database.SaveResult
Status result for the insert operation. The result corresponds to the record processed by this asynchronous operation and is associated with a unique identifier (asyncLocator). The asyncLocator value is included in the errors array of the result. You can retrieve this identifier with Database.getAsyncLocator(). Retrieve the final result with Database.getAsyncSaveResult().
Database.insertAsync() methods can’t be executed in the context of a portal user, even when the portal user is a community member. To add external object records via Apex, use Database.insertImmediate() methods.
Initiates requests to add external object data to the relevant external systems. The requests are executed asynchronously, as background operations, and are sent to the external systems that are defined by the external objects’ associated external data sources.
public static List<Database.SaveResult> insertAsync(List<SObject> sobjects, System.AccessLevel accessLevel)
-
sobjects:
Type: List<SObject>
List of external object records to insert.
-
accessLevel:
Type: System.AccessLevel
(Optional) The accessLevel parameter specifies whether the method runs in system mode (
AccessLevel.SYSTEM_MODE) or user mode (AccessLevel.USER_MODE). In system mode, the object and field-level permissions of the current user are ignored, and the record sharing rules are controlled by the class sharing keywords. In user mode, the object permissions, field-level security, and sharing rules of the current user are enforced. User mode is the default.
Type: List<Database.SaveResult>
Status results for the insert operation. Each result corresponds to a record processed by this asynchronous operation and is associated with a unique identifier (asyncLocator). The asyncLocator value is included in the errors array of the result. You can retrieve this identifier with Database.getAsyncLocator(). Retrieve the final result with Database.getAsyncSaveResult().
Database.insertAsync() methods can’t be executed in the context of a portal user, even when the portal user is a community member. To add external object records via Apex, use Database.insertImmediate() methods.
Initiates a request to add external object data to the relevant external system. The request is executed asynchronously, as a background operation, and is sent to the external system that’s defined by the external object’s associated external data source.
public static Database.SaveResult insertAsync(SObject sobject, System.AccessLevel accessLevel)
-
sobject:
Type: SObject
The external object record to insert.
-
accessLevel:
Type: System.AccessLevel
(Optional) The accessLevel parameter specifies whether the method runs in system mode (
AccessLevel.SYSTEM_MODE) or user mode (AccessLevel.USER_MODE). In system mode, the object and field-level permissions of the current user are ignored, and the record sharing rules are controlled by the class sharing keywords. In user mode, the object permissions, field-level security, and sharing rules of the current user are enforced. User mode is the default.
Type: Database.SaveResult
Status result for the insert operation. The result corresponds to the record processed by this asynchronous operation and is associated with a unique identifier (asyncLocator). The asyncLocator value is included in the errors array of the result. You can retrieve this identifier with Database.getAsyncLocator(). Retrieve the final result with Database.getAsyncSaveResult().
Database.insertAsync() methods can’t be executed in the context of a portal user, even when the portal user is a community member. To add external object records via Apex, use Database.insertImmediate() methods.
Initiates requests to add external object data to the relevant external systems. The requests are executed synchronously and are sent to the external systems that are defined by the external objects’ associated external data sources. If the Apex transaction contains pending changes, the synchronous operations can’t be completed and throw exceptions.
public static List<Database.SaveResult> insertImmediate(List<SObject> sobjects)
-
sobjects:
Type: List<SObject>
List of external object records to insert.
Type: List<Database.SaveResult>
Status results for the insert operation.
The operation allows partial success. If one or more record inserts fail, the method doesn’t throw an exception and the remainder of the DML operation can still succeed. The returned SaveResult objects indicate whether the operation was successful. If it wasn’t successful, the objects also return the error code and description.
Initiates a request to add external object data to the relevant external system. The request is executed synchronously and is sent to the external system that’s defined by the external object’s associated external data source. If the Apex transaction contains pending changes, the synchronous operation can’t be completed and throws an exception.
public static Database.SaveResult insertImmediate(SObject sobject)
-
sobject:
Type: SObject
The external object record to insert.
Type: Database.SaveResult
Status result for the insert operation.
If a record insert fails, the method doesn’t throw an exception. The returned SaveResult object indicates whether the operation was successful. If it wasn’t successful, the object returns the error code and description.
Initiates requests to add external object data to the relevant external systems. The requests are executed synchronously and are sent to the external systems that are defined by the external objects’ associated external data sources. If the Apex transaction contains pending changes, the synchronous operations can’t be completed and throw exceptions.
public static List<Database.SaveResult> insertImmediate(List<SObject> sobjects, System.AccessLevel accessLevel)
-
sobjects:
Type: List<SObject>
List of external object records to insert.
-
accessLevel:
Type: System.AccessLevel
(Optional) The accessLevel parameter specifies whether the method runs in system mode (
AccessLevel.SYSTEM_MODE) or user mode (AccessLevel.USER_MODE). In system mode, the object and field-level permissions of the current user are ignored, and the record sharing rules are controlled by the class sharing keywords. In user mode, the object permissions, field-level security, and sharing rules of the current user are enforced. User mode is the default.
Type: List<Database.SaveResult>
Status results for the insert operation.
The operation allows partial success. If one or more record inserts fail, the method doesn’t throw an exception and the remainder of the DML operation can still succeed. The returned SaveResult objects indicate whether the operation was successful. If it wasn’t successful, the objects also return the error code and description.
Initiates a request to add external object data to the relevant external system. The request is executed synchronously and is sent to the external system that’s defined by the external object’s associated external data source. If the Apex transaction contains pending changes, the synchronous operation can’t be completed and throws an exception.
public static Database.SaveResult insertImmediate(SObject sobject, System.AccessLevel accessLevel)
-
sobject:
Type: SObject
The external object record to insert.
-
accessLevel:
Type: System.AccessLevel
(Optional) The accessLevel parameter specifies whether the method runs in system mode (
AccessLevel.SYSTEM_MODE) or user mode (AccessLevel.USER_MODE). In system mode, the object and field-level permissions of the current user are ignored, and the record sharing rules are controlled by the class sharing keywords. In user mode, the object permissions, field-level security, and sharing rules of the current user are enforced. User mode is the default.
Type: Database.SaveResult
Status result for the insert operation.
If a record update fails, the method doesn’t throw an exception. The returned SaveResult object indicates whether the operation was successful. If it failed, the object returns the error code and description.
Merges the duplicate record into the mergeToRecord sObject record of the same type, deleting the duplicate, and reparenting any related records. Merges only accounts, contacts, or leads.
public static Database.MergeResult merge(sObject mergeToRecord, Id duplicateId)
-
mergeToRecord:
Type: sObject
The sObject record that the duplicate record is merged into.
-
duplicateId:
Type: ID
The ID of the record to merge with the mergeToRecord. This record must be of the same sObject type as the mergeToRecord.
Type: Database.MergeResult
Each executed merge method counts against the governor limit for DML statements.
Merges the duplicate sObject record into the mergeToRecord sObject record of the same type, deleting the duplicate, and reparenting any related records.
public static Database.MergeResult merge(sObject mergeToRecord, sObject duplicateRecord)
-
mergeToRecord:
Type: sObject
The sObject record that the duplicate record is merged into.
-
duplicateRecord:
Type: sObject
The sObject record to merge with the mergeToRecord. This sObject must be of the same type as the mergeToRecord.
Type: Database.MergeResult
Each executed merge method counts against the governor limit for DML statements.
Merges up to two records of the same sObject type into the mergeToRecord sObject record, deleting the others, and reparenting any related records.
public static List<Database.MergeResult> merge(sObject mergeToRecord, List<Id> duplicateIds)
-
mergeToRecord:
Type: SObject
The sObject record that the other records are merged into.
-
duplicateIds:
A list of IDs of up to two records to merge with the mergeToRecord. These records must be of the same sObject type as the mergeToRecord.
Type: List<Database.MergeResult>
Each executed merge method counts against the governor limit for DML statements.
Merges up to two records of the same object type into the mergeToRecord sObject record, deleting the others, and reparenting any related records.
public static List<Database.MergeResult> merge(sObject mergeToRecord, List<SObject> duplicateRecords)
-
mergeToRecord:
Type: SObject
The sObject record that the other sObjects are merged into.
-
duplicateRecords:
A list of up to two sObject records to merge with the mergeToRecord. These sObjects must be of the same type as the mergeToRecord.
Type: List<Database.MergeResult>
Each executed merge method counts against the governor limit for DML statements.
Merges the duplicate record into the mergeToRecord sObject record of the same type, optionally returning any errors, deleting the duplicate, and reparenting any related records. Merges only accounts, contacts, or leads.
public static Database.MergeResult merge(sObject mergeToRecord, Id duplicateId, Boolean allOrNone)
-
mergeToRecord:
Type: sObject
The sObject record that the duplicate record is merged into.
-
duplicate:
Type: ID
The ID of the record to merge with the mergeToRecord. This record must be of the same sObject type as the mergeToRecord.
-
allOrNone:
Type: Boolean
Type: Database.MergeResult
Each executed merge method counts against the governor limit for DML statements.
Merges the duplicate sObject record into the mergeToRecord sObject of the same type, optionally returning any errors, deleting the duplicate, and reparenting any related records.
public static Database.MergeResult merge(sObject mergeToRecord, sObject duplicateRecord, Boolean allOrNone)
-
mergeToRecord:
Type: sObject
The sObject record that the duplicate record is merged into.
-
duplicateRecord:
Type: sObject
The sObject record to merge with the mergeToRecord. This sObject must be of the same type as the mergeToRecord.
-
allOrNone:
Type: Boolean
Type: Database.MergeResult
Each executed merge method counts against the governor limit for DML statements.
Merges up to two records of the same sObject type into the mergeToRecord sObject record, optionally returning any errors, deleting the duplicates, and reparenting any related records.
public static List<Database.MergeResult> merge(sObject mergeToRecord, List<Id> duplicateIds, Boolean allOrNone)
-
mergeToRecord:
Type: SObject
The sObject record that the other records are merged into.
-
duplicateIds:
A list of IDs of up to two records to merge with the mergeToRecord. These records must be of the same sObject type as the mergeToRecord.
-
allOrNone:
Type: Boolean
Type: List<Database.MergeResult>
Each executed merge method counts against the governor limit for DML statements.
Merges up to two records of the same object type into the mergeToRecord sObject record, optionally returning any errors, deleting the duplicates, and reparenting any related records.
public static List<Database.MergeResult> merge(sObject mergeToRecord, List<SObject> duplicateRecords, Boolean allOrNone)
-
mergeToRecord:
Type: sObject
The sObject record that the other sObjects are merged into.
-
duplicateRecords:
A list of up to two sObject records to merge with the mergeToRecord. These sObjects must be of the same type as the mergeToRecord.
-
allOrNone:
Type: Boolean
Type: List<Database.MergeResult>
Each executed merge method counts against the governor limit for DML statements.
Merges the duplicate record into the mergeToRecord sObject record of the same type, deleting the duplicate, and reparenting any related records. Merges only accounts, contacts, or leads.
public static Database.MergeResult merge(SObject mergeToRecord, Id duplicateId, System.AccessLevel accessLevel)
-
mergeToRecord:
Type: sObject
The sObject record that the duplicate record is merged into.
-
duplicateId:
Type: ID
The ID of the record to merge with the mergeToRecord. This record must be of the same sObject type as the mergeToRecord.
-
accessLevel:
Type: System.AccessLevel
(Optional) The accessLevel parameter specifies whether the method runs in system mode (
AccessLevel.SYSTEM_MODE) or user mode (AccessLevel.USER_MODE). In system mode, the object and field-level permissions of the current user are ignored, and the record sharing rules are controlled by the class sharing keywords. In user mode, the object permissions, field-level security, and sharing rules of the current user are enforced. User mode is the default.
Type: Database.MergeResult
Each executed merge method counts against the governor limit for DML statements.
Merges the specified duplicate sObject record into the mergeToRecord sObject of the same type, deleting the duplicate, and reparenting any related records.
public static Database.MergeResult merge(SObject mergeToRecord, SObject duplicateRecord, System.AccessLevel accessLevel)
-
mergeToRecord:
Type: sObject
The sObject record that the duplicate record is merged into.
-
duplicateRecord:
Type: sObject
The sObject record to merge with the mergeToRecord. This sObject must be of the same type as the mergeToRecord.
-
accessLevel:
Type: System.AccessLevel
(Optional) The accessLevel parameter specifies whether the method runs in system mode (
AccessLevel.SYSTEM_MODE) or user mode (AccessLevel.USER_MODE). In system mode, the object and field-level permissions of the current user are ignored, and the record sharing rules are controlled by the class sharing keywords. In user mode, the object permissions, field-level security, and sharing rules of the current user are enforced. User mode is the default.
Type: Database.MergeResult
Each executed merge method counts against the governor limit for DML statements.
Merges up to two records of the same sObject type into the mergeToRecord sObject record, deleting the others, and reparenting any related records.
public static List<Database.MergeResult> merge(SObject mergeToRecord, List<Id> duplicateIds, System.AccessLevel accessLevel)
-
mergeToRecord:
Type: SObject
The sObject record that the other records are merged into.
-
duplicateIds:
Type: List<Id> A list of IDs of up to two records to merge with the mergeToRecord. These records must be of the same sObject type as the mergeToRecord.
-
accessLevel:
Type: System.AccessLevel
(Optional) The accessLevel parameter specifies whether the method runs in system mode (
AccessLevel.SYSTEM_MODE) or user mode (AccessLevel.USER_MODE). In system mode, the object and field-level permissions of the current user are ignored, and the record sharing rules are controlled by the class sharing keywords. In user mode, the object permissions, field-level security, and sharing rules of the current user are enforced. User mode is the default.
Type: List<Database.MergeResult>
Each executed merge method counts against the governor limit for DML statements.
Merges up to two records of the same object type into the mergeToRecord sObject record, deleting the others, and reparenting any related records.
public static List<Database.MergeResult> merge(SObject mergeToRecord, List<SObject> duplicateRecords, System.AccessLevel accessLevel)
-
mergeToRecord:
Type: SObject
The sObject that the other sObject records are merged into.
-
duplicateRecords:
Type: List<SObject> A list of up to two sObject records to merge with the mergeToRecord. These sObjects must be of the same type as the mergeToRecord.
-
accessLevel:
Type: System.AccessLevel
(Optional) The accessLevel parameter specifies whether the method runs in system mode (
AccessLevel.SYSTEM_MODE) or user mode (AccessLevel.USER_MODE). In system mode, the object and field-level permissions of the current user are ignored, and the record sharing rules are controlled by the class sharing keywords. In user mode, the object permissions, field-level security, and sharing rules of the current user are enforced. User mode is the default.
Type: List<Database.MergeResult>
Each executed merge method counts against the governor limit for DML statements.
Merges the duplicate record into the mergeToRecord sObject record of the same type, optionally returning any errors, deleting the duplicate, and reparenting any related records. Merges only accounts, contacts, or leads.
public static Database.MergeResult merge(SObject mergeToRecord, Id duplicateId, Boolean allOrNone, System.AccessLevel accessLevel)
-
mergeToRecord:
Type: sObject
The sObject record that the duplicate record is merged into.
-
duplicateId:
Type: ID
The ID of the record to merge with the mergeToRecord. This record must be of the same sObject type as the mergeToRecord.
-
allOrNone:
Type: Boolean
-
accessLevel:
Type: System.AccessLevel
(Optional) The accessLevel parameter specifies whether the method runs in system mode (
AccessLevel.SYSTEM_MODE) or user mode (AccessLevel.USER_MODE). In system mode, the object and field-level permissions of the current user are ignored, and the record sharing rules are controlled by the class sharing keywords. In user mode, the object permissions, field-level security, and sharing rules of the current user are enforced. User mode is the default.
Type: Database.MergeResult
If you use the accessLevel parameter to specify that the method runs in user mode, we report all encountered inaccessible fields. The way to retrieve the names of these inaccessible fields depends on the value of this method’s allOrNone parameter, or the equivalent DmlOptions.optAllOrNone property. If you specify that:
allOrNone=trueorDmlOptions.optAllOrNone=true: Catch theDMLExceptionand use theDMLException.getDMLFieldNames()method to retrieve the list of inaccessible fields. See Exception Class and Built-In Exceptions for more information.allOrNone=falseorDmlOptions.optAllOrNone=false: For each failing record, we update theDatabase.Errorobject that results from the DML operation. Use theError.getFields()method to retrieve the list of inaccessible fields. See the Error Class methods for more information.
Each executed merge method counts against the governor limit for DML statements.
Merges the duplicate sObject record into the mergeToRecord sObject record of the same type, optionally returning any errors, deleting the duplicate, and reparenting any related records.
public static Database.MergeResult merge(SObject mergeToRecord, SObject duplicateRecord, Boolean allOrNone, System.AccessLevel accessLevel)
-
mergeToRecord:
Type: sObject
The sObject record that the duplicate record is merged into.
-
duplicateRecord:
Type: sObject
The sObject record to merge with the mergeToRecord. This sObject must be of the same type as the mergeToRecord.
-
allOrNone:
Type: Boolean
-
accessLevel:
Type: System.AccessLevel
(Optional) The accessLevel parameter specifies whether the method runs in system mode (
AccessLevel.SYSTEM_MODE) or user mode (AccessLevel.USER_MODE). In system mode, the object and field-level permissions of the current user are ignored, and the record sharing rules are controlled by the class sharing keywords. In user mode, the object permissions, field-level security, and sharing rules of the current user are enforced. User mode is the default.
Type: Database.MergeResult
If you use the accessLevel parameter to specify that the method runs in user mode, we report all encountered inaccessible fields. The way to retrieve the names of these inaccessible fields depends on the value of this method’s allOrNone parameter, or the equivalent DmlOptions.optAllOrNone property. If you specify that:
allOrNone=trueorDmlOptions.optAllOrNone=true: Catch theDMLExceptionand use theDMLException.getDMLFieldNames()method to retrieve the list of inaccessible fields. See Exception Class and Built-In Exceptions for more information.allOrNone=falseorDmlOptions.optAllOrNone=false: For each failing record, we update theDatabase.Errorobject that results from the DML operation. Use theError.getFields()method to retrieve the list of inaccessible fields. See the Error Class methods for more information.
Each executed merge method counts against the governor limit for DML statements.
Merges up to two records of the same sObject type into the mergeToRecord sObject record, optionally returning any errors, deleting the duplicates, and reparenting any related records.
public static List<Database.MergeResult> merge(SObject mergeToRecord, List<Id> duplicateIds, Boolean allOrNone, System.AccessLevel accessLevel)
-
mergeToRecord:
Type: SObject
The sObject record that the other records are merged into.
-
duplicateIds:
Type: List<Id> A list of IDs of up to two records to merge with the mergeToRecord. These records must be of the same sObject type as the mergeToRecord.
-
allOrNone:
Type: Boolean
-
accessLevel:
Type: System.AccessLevel
(Optional) The accessLevel parameter specifies whether the method runs in system mode (
AccessLevel.SYSTEM_MODE) or user mode (AccessLevel.USER_MODE). In system mode, the object and field-level permissions of the current user are ignored, and the record sharing rules are controlled by the class sharing keywords. In user mode, the object permissions, field-level security, and sharing rules of the current user are enforced. User mode is the default.
Type: List<Database.MergeResult>
If you use the accessLevel parameter to specify that the method runs in user mode, we report all encountered inaccessible fields. The way to retrieve the names of these inaccessible fields depends on the value of this method’s allOrNone parameter, or the equivalent DmlOptions.optAllOrNone property. If you specify that:
allOrNone=trueorDmlOptions.optAllOrNone=true: Catch theDMLExceptionand use theDMLException.getDMLFieldNames()method to retrieve the list of inaccessible fields. See Exception Class and Built-In Exceptions for more information.allOrNone=falseorDmlOptions.optAllOrNone=false: For each failing record, we update theDatabase.Errorobject that results from the DML operation. Use theError.getFields()method to retrieve the list of inaccessible fields. See the Error Class methods for more information.
Each executed merge method counts against the governor limit for DML statements.
Merges up to two records of the same object type into the mergeToRecord sObject record, optionally returning any errors, deleting the duplicates, and reparenting any related records.
public static List<Database.MergeResult> merge(SObject mergeToRecord, List<SObject> duplicateRecords, Boolean allOrNone, System.AccessLevel accessLevel)
-
mergeToRecord:
Type: sObject
The sObject record that the other sObjects are merged into.
-
duplicateRecords:
Type: List<SObject> A list of up to two sObject records to merge with the mergeToRecord. These sObjects must be of the same type as the mergeToRecord.
-
allOrNone:
Type: Boolean
-
accessLevel:
Type: System.AccessLevel
(Optional) The accessLevel parameter specifies whether the method runs in system mode (
AccessLevel.SYSTEM_MODE) or user mode (AccessLevel.USER_MODE). In system mode, the object and field-level permissions of the current user are ignored, and the record sharing rules are controlled by the class sharing keywords. In user mode, the object permissions, field-level security, and sharing rules of the current user are enforced. User mode is the default.
Type: List<Database.MergeResult>
If you use the accessLevel parameter to specify that the method runs in user mode, we report all encountered inaccessible fields. The way to retrieve the names of these inaccessible fields depends on the value of this method’s allOrNone parameter, or the equivalent DmlOptions.optAllOrNone property. If you specify that:
allOrNone=trueorDmlOptions.optAllOrNone=true: Catch theDMLExceptionand use theDMLException.getDMLFieldNames()method to retrieve the list of inaccessible fields. See Exception Class and Built-In Exceptions for more information.allOrNone=falseorDmlOptions.optAllOrNone=false: For each failing record, we update theDatabase.Errorobject that results from the DML operation. Use theError.getFields()method to retrieve the list of inaccessible fields. See the Error Class methods for more information.
Each executed merge method counts against the governor limit for DML statements.
Creates a dynamic SOQL query at runtime.
public static List<SObject> query(String queryString)
-
queryString:
Type: String
This method can be used wherever a static SOQL query can be used, such as in regular assignment statements and for loops. Unlike inline SOQL, fields in bind variables aren’t supported. For more information, see Dynamic SOQL.
Database.query() calls containing an inner query for a related child object may not return the entire result set based on the size and complexity of the records requested. Instead, use Database.getQueryLocator() in conjunction with Apex Batch. Alternatively, you can use the same SOQL query with SOAP API to be able to access all the resulting records.
Each executed query method counts against the governor limit for SOQL queries.
Creates a dynamic SOQL query at runtime.
public static List<SObject> query(String queryString, System.AccessLevel accessLevel)
-
queryString:
Type: String
-
accessLevel:
Type: System.AccessLevel
(Optional) The accessLevel parameter specifies whether the method runs in system mode (
AccessLevel.SYSTEM_MODE) or user mode (AccessLevel.USER_MODE). In system mode, the object and field-level permissions of the current user are ignored, and the record sharing rules are controlled by the class sharing keywords. In user mode, the object permissions, field-level security, and sharing rules of the current user are enforced. User mode is the default.
This method can be used wherever a static SOQL query can be used, such as in regular assignment statements and for loops. Unlike inline SOQL, fields in bind variables aren’t supported. For more information, see Dynamic SOQL.
Database.query() calls containing an inner query for a related child object may not return the entire result set based on the size and complexity of the records requested. Instead, use Database.getQueryLocator() in conjunction with Apex Batch. Alternatively, you can use the same SOQL query with SOAP API to be able to access all the resulting records.
Each executed query method counts against the governor limit for SOQL queries.
Creates a dynamic SOQL query at runtime. Bind variables in the query are resolved from the bindMap Map parameter directly with the key, rather than from Apex code variables.
public static List<SObject> queryWithBinds(String queryString, Map<String, Object> bindMap, System.AccessLevel accessLevel)
-
queryString:
Type: String
SOQL query that includes Apex bind variables or expressions preceded by a colon. All bind variables must have a key in the bindMap Map.
-
bindMap:
Type: Map<String, Object> A map that contains keys for each bind variable specified in the SOQL queryString and its value. The keys can’t be null or duplicates, and the values can’t be null or empty strings.
-
accessLevel:
Type: System.AccessLevel
The accessLevel parameter specifies whether the method runs in system mode (
AccessLevel.SYSTEM_MODE) or user mode (AccessLevel.USER_MODE). In system mode, the object and field-level permissions of the current user are ignored, and the record sharing rules are controlled by the class sharing keywords. In user mode, the object permissions, field-level security, and sharing rules of the current user are enforced.
This method can be used wherever a static SOQL query can be used, such as in regular assignment statements and for loops.
For more information, see Dynamic SOQL.
Each executed queryWithBinds method counts against the governor limit for SOQL queries.
In this example, the SOQL query uses a bind variable for an Account name. Its value (Acme Inc.) is passed in to the method using the nameBind Map. The accountName variable isn’t (and doesn’t have to be) in scope when the query is executed within the method.
Releases a given savepoint. All savepoints that are subsequent to the given one are also released.
public static void releaseSavepoint(System.Savepoint databaseSavepoint)
-
databaseSavepoint:
Type: System.Savepoint
Type: void
For Apex tests with API version 60.0 or later, all savepoints are released when Test.startTest() and Test.stopTest() are called. If any savepoints are reset, a SAVEPOINT_RESET event is logged.
Before API version 60.0, making a callout after creating savepoints throws a CalloutException regardless of whether there was uncommitted DML or the changes were rolled back to a savepoint. Also, before API version 60.0, both Database.rollback(databaseSavepoint) and Database.setSavepoint() calls incremented the DML row usage limit.
Restores the database to the state specified by the savepoint variable. Any emails submitted since the last savepoint are also rolled back and not sent.
public static Void rollback(System.Savepoint databaseSavepoint)
-
databaseSavepoint:
Type: System.Savepoint
Type: Void
Note the following:
-
Static variables aren’t reverted during a rollback. If you try to run the trigger again, the static variables retain the values from the first run.
-
Each rollback counts against the governor limit for DML statements. You receive a runtime error if you try to roll back the database additional times.
-
The ID on an sObject inserted after setting a savepoint isn’t cleared after a rollback. Create an sObject to insert after a rollback. Attempting to insert the sObject using the variable created before the rollback fails because the sObject variable has an ID. Updating or upserting the sObject using the same variable also fails because the sObject isn’t in the database and, thus, can’t be updated.
For an example, see Transaction Control.
For Apex tests with API version 60.0 or later, all savepoints are released when Test.startTest() and Test.stopTest() are called. If any savepoints are reset, a SAVEPOINT_RESET event is logged.
Before API version 60.0, making a callout after creating savepoints throws a CalloutException regardless of whether there was uncommitted DML or the changes were rolled back to a savepoint. Also, before API version 60.0, both Database.rollback(Savepoint) and Database.setSavepoint() calls incremented the DML row usage limit.
Returns a savepoint variable that can be stored as a local variable, then used with the rollback method to restore the database to that point.
public static System.Savepoint setSavepoint()
Type: System.Savepoint
Note the following:
- If you set more than one savepoint, then roll back to a savepoint that isn’t the last savepoint you generated, the later savepoint variables become invalid. For example, if you generated savepoint
SP1first, savepointSP2after that, and then you rolled back toSP1, the variableSP2would no longer be valid. You receive a runtime error if you try to use it. - References to savepoints can’t cross trigger invocations because each trigger invocation is a new trigger context. If you declare a savepoint as a static variable then try to use it across trigger contexts, you receive a run-time error.
- Each savepoint you set counts against the governor limit for DML statements.
- When you call
IntegrationTest.commitTestOnly(), active savepoints created withDatabase.setSavepoint()are committed and released. See Apex Integration Tests (Developer Preview).
For an example, see Transaction Control.
For Apex tests with API version 60.0 or later, all savepoints are released when Test.startTest() and Test.stopTest() are called. If any savepoints are reset, a SAVEPOINT_RESET event is logged.
Before API version 60.0, making a callout after creating savepoints throws a CalloutException regardless of whether there was uncommitted DML or the changes were rolled back to a savepoint. Also, before API version 60.0, both Database.rollback(Savepoint) and Database.setSavepoint() calls incremented the DML row usage limit.
Restores an existing sObject record, such as an individual account or contact, from your organization’s Recycle Bin.
public static Database.UndeleteResult undelete(sObject recordToUndelete, Boolean allOrNone)
Type: Database.UndeleteResult
undelete is analogous to the UNDELETE statement in SQL.
Each executed undelete method counts against the governor limit for DML statements.
Restores one or more existing sObject records, such as individual accounts or contacts, from your organization’s Recycle Bin.
public static Database.UndeleteResult[] undelete(sObject[] recordsToUndelete, Boolean allOrNone)
Type: Database.UndeleteResult[]
undelete is analogous to the UNDELETE statement in SQL.
Each executed undelete method counts against the governor limit for DML statements.
The following example restores all accounts named ‘Universal Containers’. The ALL ROWS keyword queries all rows for both top-level and aggregate relationships, including deleted records and archived activities.
Restores an existing sObject record, such as an individual account or contact, from your organization’s Recycle Bin.
public static Database.UndeleteResult undelete(ID recordID, Boolean allOrNone)
Type: Database.UndeleteResult
undelete is analogous to the UNDELETE statement in SQL.
Each executed undelete method counts against the governor limit for DML statements.
Restores one or more existing sObject records, such as individual accounts or contacts, from your organization’s Recycle Bin.
public static Database.UndeleteResult[] undelete(ID[] recordIDs, Boolean allOrNone)
Type: Database.UndeleteResult[]
undelete is analogous to the UNDELETE statement in SQL.
Each executed undelete method counts against the governor limit for DML statements.
Restores an existing sObject record, such as an individual account or contact, from your organization’s Recycle Bin.
public static Database.UndeleteResult undelete(SObject recordToUndelete, Boolean allOrNone, System.AccessLevel accessLevel)
-
recordToUndelete:
Type: SObject
-
allOrNone:
Type: Boolean
-
accessLevel:
Type: System.AccessLevel
(Optional) The accessLevel parameter specifies whether the method runs in system mode (
AccessLevel.SYSTEM_MODE) or user mode (AccessLevel.USER_MODE). In system mode, the object and field-level permissions of the current user are ignored, and the record sharing rules are controlled by the class sharing keywords. In user mode, the object permissions, field-level security, and sharing rules of the current user are enforced. User mode is the default.
Type: Database.UndeleteResult
undelete is analogous to the UNDELETE statement in SQL.
Each executed undelete method counts against the governor limit for DML statements.
Restores one or more existing sObject records, such as individual accounts or contacts, from your organization’s Recycle Bin.
public static List<Database.UndeleteResult> undelete(List<SObject> recordsToUndelete, Boolean allOrNone, System.AccessLevel accessLevel)
-
recordsToUndelete:
Type: List<sObject>
-
allOrNone:
Type: Boolean
-
accessLevel:
Type: System.AccessLevel
(Optional) The accessLevel parameter specifies whether the method runs in system mode (
AccessLevel.SYSTEM_MODE) or user mode (AccessLevel.USER_MODE). In system mode, the object and field-level permissions of the current user are ignored, and the record sharing rules are controlled by the class sharing keywords. In user mode, the object permissions, field-level security, and sharing rules of the current user are enforced. User mode is the default.
Type: List<Database.UndeleteResult>
undelete is analogous to the UNDELETE statement in SQL.
Each executed undelete method counts against the governor limit for DML statements.
Restores an existing sObject record, such as an individual account or contact, from your organization’s Recycle Bin.
public static Database.UndeleteResult undelete(Id recordID, Boolean allOrNone, System.AccessLevel accessLevel)
-
recordID:
Type: Id
-
allOrNone:
Type: Boolean
-
accessLevel:
Type: System.AccessLevel
(Optional) The accessLevel parameter specifies whether the method runs in system mode (
AccessLevel.SYSTEM_MODE) or user mode (AccessLevel.USER_MODE). In system mode, the object and field-level permissions of the current user are ignored, and the record sharing rules are controlled by the class sharing keywords. In user mode, the object permissions, field-level security, and sharing rules of the current user are enforced. User mode is the default.
Type: Database.UndeleteResult
undelete is analogous to the UNDELETE statement in SQL.
Each executed undelete method counts against the governor limit for DML statements.
Restores one or more existing sObject records, such as individual accounts or contacts, from your organization’s Recycle Bin.
public static List<Database.UndeleteResult> undelete(List<Id> recordIDs, Boolean allOrNone, System.AccessLevel accessLevel)
-
recordIDs:
Type: List<ID>
-
allOrNone:
Type: Boolean
-
accessLevel:
Type: System.AccessLevel
(Optional) The accessLevel parameter specifies whether the method runs in system mode (
AccessLevel.SYSTEM_MODE) or user mode (AccessLevel.USER_MODE). In system mode, the object and field-level permissions of the current user are ignored, and the record sharing rules are controlled by the class sharing keywords. In user mode, the object permissions, field-level security, and sharing rules of the current user are enforced. User mode is the default.
Type: List<Database.UndeleteResult>
undelete is analogous to the UNDELETE statement in SQL.
Each executed undelete method counts against the governor limit for DML statements.
Modifies an existing sObject record, such as an individual account or contact, in your organization’s data.
public static Database.SaveResult update(sObject recordToUpdate, Boolean allOrNone)
Type: Database.SaveResult
update is analogous to the UPDATE statement in SQL.
Apex classes and triggers saved (compiled) using API version 15.0 and higher produce a runtime error if you assign a String value that is too long for the field.
Each executed update method counts against the governor limit for DML statements.
The following example updates the BillingCity field on a single account.
Modifies one or more existing sObject records, such as individual accounts or contacts, in your organization’s data.
public static Database.SaveResult[] update(sObject[] recordsToUpdate, Boolean allOrNone)
Type: Database.SaveResult[]
update is analogous to the UPDATE statement in SQL.
Each executed update method counts against the governor limit for DML statements.
Modifies an existing sObject record, such as an individual account or contact, in your organization’s data.
public static Database.SaveResult update(sObject recordToUpdate, Database.DmlOptions dmlOptions)
-
recordToUpdate:
Type: sObject
-
dmlOptions:
Type: Database.DMLOptions
The optional dmlOptions parameter specifies additional data for the transaction, such as assignment rule information or rollback behavior when errors occur during record insertions.
Type: Database.SaveResult
update is analogous to the UPDATE statement in SQL.
Apex classes and triggers saved (compiled) using API version 15.0 and higher produce a runtime error if you assign a String value that is too long for the field.
Each executed update method counts against the governor limit for DML statements.
Modifies one or more existing sObject records, such as individual accounts or contacts, in your organization’s data.
public static Database.SaveResult[] update(sObject[] recordsToUpdate, Database.DMLOptions dmlOptions)
-
recordsToUpdate:
Type: sObject []
-
dmlOptions:
Type: Database.DMLOptions
The optional dmlOptions parameter specifies additional data for the transaction, such as assignment rule information or rollback behavior when errors occur during record insertions.
Type: Database.SaveResult[]
update is analogous to the UPDATE statement in SQL.
Apex classes and triggers saved (compiled) using API version 15.0 and higher produce a runtime error if you assign a String value that is too long for the field.
Each executed update method counts against the governor limit for DML statements.
Modifies an existing sObject record, such as an individual account or contact, in your organization’s data.
public static Database.SaveResult update(SObject recordToUpdate, Boolean allOrNone, System.AccessLevel accessLevel)
-
recordToUpdate:
Type: SObject
-
allOrNone:
Type: Boolean
-
accessLevel:
Type: System.AccessLevel
(Optional) The accessLevel parameter specifies whether the method runs in system mode (
AccessLevel.SYSTEM_MODE) or user mode (AccessLevel.USER_MODE). In system mode, the object and field-level permissions of the current user are ignored, and the record sharing rules are controlled by the class sharing keywords. In user mode, the object permissions, field-level security, and sharing rules of the current user are enforced. User mode is the default.
Type: Database.SaveResult
If you use the accessLevel parameter to specify that the method runs in user mode, we report all encountered inaccessible fields. The way to retrieve the names of these inaccessible fields depends on the value of this method’s allOrNone parameter, or the equivalent DmlOptions.optAllOrNone property. If you specify that:
allOrNone=trueorDmlOptions.optAllOrNone=true: Catch theDMLExceptionand use theDMLException.getDMLFieldNames()method to retrieve the list of inaccessible fields. See Exception Class and Built-In Exceptions for more information.allOrNone=falseorDmlOptions.optAllOrNone=false: For each failing record, we update theDatabase.Errorobject that results from the DML operation. Use theError.getFields()method to retrieve the list of inaccessible fields. See the Error Class methods for more information.
Modifies one or more existing sObject records, such as individual accounts or contacts, in your organization’s data.
public static List<Database.SaveResult> update(List<SObject> recordsToUpdate, Boolean allOrNone, System.AccessLevel accessLevel)
-
recordsToUpdate:
Type: List<sObject>
-
allOrNone:
Type: Boolean
-
accessLevel:
Type: System.AccessLevel
(Optional) The accessLevel parameter specifies whether the method runs in system mode (
AccessLevel.SYSTEM_MODE) or user mode (AccessLevel.USER_MODE). In system mode, the object and field-level permissions of the current user are ignored, and the record sharing rules are controlled by the class sharing keywords. In user mode, the object permissions, field-level security, and sharing rules of the current user are enforced. User mode is the default.
Type: List<Database.SaveResult>
If you use the accessLevel parameter to specify that the method runs in user mode, we report all encountered inaccessible fields. The way to retrieve the names of these inaccessible fields depends on the value of this method’s allOrNone parameter, or the equivalent DmlOptions.optAllOrNone property. If you specify that:
allOrNone=trueorDmlOptions.optAllOrNone=true: Catch theDMLExceptionand use theDMLException.getDMLFieldNames()method to retrieve the list of inaccessible fields. See Exception Class and Built-In Exceptions for more information.allOrNone=falseorDmlOptions.optAllOrNone=false: For each failing record, we update theDatabase.Errorobject that results from the DML operation. Use theError.getFields()method to retrieve the list of inaccessible fields. See the Error Class methods for more information.
Modifies an existing sObject record, such as an individual account or contact, in your organization’s data.
public static Database.SaveResult update(SObject recordToUpdate, Database.DMLOptions dmlOptions, System.AccessLevel accessLevel)
-
recordToUpdate:
Type: SObject
-
dmlOptions:
Type: Database.DMLOptions
The optional dmlOptions parameter specifies additional data for the transaction, such as assignment rule information or rollback behavior when errors occur during record insertions.
-
accessLevel:
Type: System.AccessLevel
(Optional) The accessLevel parameter specifies whether the method runs in system mode (
AccessLevel.SYSTEM_MODE) or user mode (AccessLevel.USER_MODE). In system mode, the object and field-level permissions of the current user are ignored, and the record sharing rules are controlled by the class sharing keywords. In user mode, the object permissions, field-level security, and sharing rules of the current user are enforced. User mode is the default.
Type: Database.SaveResult
Modifies one or more existing sObject records, such as individual accounts or contacts, in your organization’s data.
public static List<Database.SaveResult> update(List<SObject> recordsToUpdate, Database.DMLOptions dmlOptions, System.AccessLevel accessLevel)
-
recordsToUpdate:
Type: List<sObject>
-
dmlOptions:
Type: Database.DMLOptions
The optional dmlOptions parameter specifies additional data for the transaction, such as assignment rule information or rollback behavior when errors occur during record insertions.
-
accessLevel:
Type: System.AccessLevel
(Optional) The accessLevel parameter specifies whether the method runs in system mode (
AccessLevel.SYSTEM_MODE) or user mode (AccessLevel.USER_MODE). In system mode, the object and field-level permissions of the current user are ignored, and the record sharing rules are controlled by the class sharing keywords. In user mode, the object permissions, field-level security, and sharing rules of the current user are enforced. User mode is the default.
Type: List<Database.SaveResult>
Creates a new sObject record or updates an existing sObject record within a single statement, using a specified field to determine the presence of existing objects, or the ID field if no field is specified.
public static Database.UpsertResult upsert(sObject recordToUpsert, Schema.SObjectField externalIDField, Boolean allOrNone)
-
recordToUpsert:
Type: sObject
-
externalIdField:
Type: Schema.SObjectField
(Optional) The externalIdField is of type
Schema.SObjectField, that is, a field token. Find the token for the field by using thefieldsspecial method. For example,Schema.SObjectField f = Account.Fields.MyExternalId. The externalIdField parameter is the field thatupsert()uses to match sObjects with existing records. This field can be a custom field marked as external ID, or a standard field with theidLookupattribute.If externalIdField isn’t specified, then the ID field is used to determine a match with existing records.
-
allOrNone:
Type: Boolean
Type: Database.UpsertResult
Apex classes and triggers saved (compiled) using API version 15.0 and higher produce a runtime error if you assign a String value that is too long for the field.
Each executed upsert method counts against the governor limit for DML statements.
For more information on how the upsert operation works, see the upsert() statement.
Creates new sObject records or updates existing sObject records within a single statement, using a specified field to determine the presence of existing objects, or the ID field if no field is specified.
public static Database.UpsertResult[] upsert(sObject[] recordsToUpsert, Schema.SObjectField externalIdField, Boolean allOrNone)
-
recordsToUpsert:
Type: sObject []
-
externalIdField:
Type: Schema.SObjectField
(Optional) The externalIdField is of type
Schema.SObjectField, that is, a field token. Find the token for the field by using thefieldsspecial method. For example,Schema.SObjectField f = Account.Fields.MyExternalId. The externalIdField parameter is the field thatupsert()uses to match sObjects with existing records. This field can be a custom field marked as external ID, or a standard field with theidLookupattribute.If externalIdField isn’t specified, then the ID field is used to determine a match with existing records.
-
allOrNone:
Type: Boolean
Type: Database.UpsertResult[]
Apex classes and triggers saved (compiled) using API version 15.0 and higher produce a runtime error if you assign a String value that is too long for the field.
Each executed upsert method counts against the governor limit for DML statements.
For more information on how the upsert operation works, see the upsert() statement.
Creates a new sObject record or updates an existing sObject record within a single statement, using a specified field to determine the presence of existing objects, or the ID field if no field is specified.
public static Database.UpsertResult upsert(SObject recordToUpsert, Schema.SObjectField externalIdField, Boolean allOrNone, System.AccessLevel accessLevel)
-
recordToUpsert:
Type: SObject
-
externalIdField:
Type: Schema.SObjectField
(Optional) The externalIdField is of type
Schema.SObjectField, that is, a field token. Find the token for the field by using thefieldsspecial method. For example,Schema.SObjectField f = Account.Fields.MyExternalId. The externalIdField parameter is the field thatupsert()uses to match sObjects with existing records. This field can be a custom field marked as external ID, or a standard field with theidLookupattribute.If externalIdField isn’t specified, then the ID field is used to determine a match with existing records.
-
allOrNone:
Type: Boolean
-
accessLevel:
Type: System.AccessLevel
(Optional) The accessLevel parameter specifies whether the method runs in system mode (
AccessLevel.SYSTEM_MODE) or user mode (AccessLevel.USER_MODE). In system mode, the object and field-level permissions of the current user are ignored, and the record sharing rules are controlled by the class sharing keywords. In user mode, the object permissions, field-level security, and sharing rules of the current user are enforced. User mode is the default.
Type: Database.UpsertResult
If you use the accessLevel parameter to specify that the method runs in user mode, we report all encountered inaccessible fields. The way to retrieve the names of these inaccessible fields depends on the value of this method’s allOrNone parameter, or the equivalent DmlOptions.optAllOrNone property. If you specify that:
allOrNone=trueorDmlOptions.optAllOrNone=true: Catch theDMLExceptionand use theDMLException.getDMLFieldNames()method to retrieve the list of inaccessible fields. See Exception Class and Built-In Exceptions for more information.allOrNone=falseorDmlOptions.optAllOrNone=false: For each failing record, we update theDatabase.Errorobject that results from the DML operation. Use theError.getFields()method to retrieve the list of inaccessible fields. See the Error Class methods for more information.
Apex classes and triggers saved (compiled) using API version 15.0 and higher produce a runtime error if you assign a String value that is too long for the field.
Each executed upsert method counts against the governor limit for DML statements.
For more information on how the upsert operation works, see the upsert() statement.
Creates new sObject records or updates existing sObject records within a single statement, using a specified field to determine the presence of existing objects, or the ID field if no field is specified.
public static List<Database.UpsertResult> upsert(List<SObject> recordsToUpsert, Schema.SObjectField externalIdField, Boolean allOrNone, System.AccessLevel accessLevel)
-
recordsToUpsert:
Type: List<sObject >
-
externalIdField:
Type: Schema.SObjectField
(Optional) The externalIdField is of type
Schema.SObjectField, that is, a field token. Find the token for the field by using thefieldsspecial method. For example,Schema.SObjectField f = Account.Fields.MyExternalId. The externalIdField parameter is the field thatupsert()uses to match sObjects with existing records. This field can be a custom field marked as external ID, or a standard field with theidLookupattribute.If externalIdField isn’t specified, then the ID field is used to determine a match with existing records.
-
allOrNone:
Type: Boolean
-
accessLevel:
Type: System.AccessLevel
(Optional) The accessLevel parameter specifies whether the method runs in system mode (
AccessLevel.SYSTEM_MODE) or user mode (AccessLevel.USER_MODE). In system mode, the object and field-level permissions of the current user are ignored, and the record sharing rules are controlled by the class sharing keywords. In user mode, the object permissions, field-level security, and sharing rules of the current user are enforced. User mode is the default.
Type: List<Database.UpsertResult>
If you use the accessLevel parameter to specify that the method runs in user mode, we report all encountered inaccessible fields. The way to retrieve the names of these inaccessible fields depends on the value of this method’s allOrNone parameter, or the equivalent DmlOptions.optAllOrNone property. If you specify that:
allOrNone=trueorDmlOptions.optAllOrNone=true: Catch theDMLExceptionand use theDMLException.getDMLFieldNames()method to retrieve the list of inaccessible fields. See Exception Class and Built-In Exceptions for more information.allOrNone=falseorDmlOptions.optAllOrNone=false: For each failing record, we update theDatabase.Errorobject that results from the DML operation. Use theError.getFields()method to retrieve the list of inaccessible fields. See the Error Class methods for more information.
Apex classes and triggers saved (compiled) using API version 15.0 and higher produce a runtime error if you assign a String value that is too long for the field.
Each executed upsert method counts against the governor limit for DML statements.
For more information on how the upsert operation works, see the upsert() statement.
Initiates requests to update external object data on the relevant external systems. The requests are executed asynchronously, as background operations, and are sent to the external systems that are defined by the external objects’ associated external data sources. Allows referencing a callback class whose processSave method is called for each record after the remote operations are completed.
public static List<Database.SaveResult> updateAsync(List<SObject> sobjects, DataSource.AsyncSaveCallback callback)
-
sobjects:
Type: List<SObject> List of external object records to modify.
-
callback:
Type: DataSource.AsyncSaveCallback
The callback object that contains the state in the originating context and an action (the
processSavemethod) that executes after the insert operation is completed. Use the action callback to update org data according to the operation’s results. The callback object must extendDataSource.AsyncSaveCallback.
Type: List<Database.SaveResult>
Status results for the update operation. Each result corresponds to a record processed by this asynchronous operation and is associated with a unique identifier (asyncLocator). The asyncLocator value is included in the errors array of the result. You can retrieve this identifier with Database.getAsyncLocator(). Retrieve the final result with Database.getAsyncSaveResult().
Initiates a request to update external object data on the relevant external system. The request is executed asynchronously, as a background operation, and is sent to the external system that’s defined by the external object’s associated external data source. Allows referencing a callback class whose processSave method is called after the remote operation is completed.
public static Database.SaveResult updateAsync(SObject sobject, DataSource.AsyncSaveCallback callback)
-
sobject:
Type: SObject External object record to modify.
-
callback:
Type: DataSource.AsyncSaveCallback
The callback object that contains the state in the originating context and an action (the
processSavemethod) that executes after the insert operation is completed. Use the action callback to update org data according to the operation’s results. The callback object must extendDataSource.AsyncSaveCallback.
Type: Database.SaveResult
Status result for the insert operation. The result corresponds to a record processed by this asynchronous operation and is associated with a unique identifier (asyncLocator). The asyncLocator value is included in the errors array of the result. You can retrieve this identifier with Database.getAsyncLocator(). Retrieve the final result with Database.getAsyncSaveResult().
Initiates requests to update external object data on the relevant external systems. The requests are executed asynchronously, as background operations, and are sent to the external systems that are defined by the external objects’ associated external data sources.
public static List<Database.SaveResult> updateAsync(List<SObject> sobjects)
-
sobjects:
Type: List<SObject>
List of external object records to modify.
Type: List<Database.SaveResult>
Status results for the update operation. Each result corresponds to a record processed by this asynchronous operation and is associated with a unique identifier (asyncLocator). The asyncLocator value is included in the errors array of the result. You can retrieve this identifier with Database.getAsyncLocator(). Retrieve the final result with Database.getAsyncSaveResult().
Initiates a request to update external object data on the relevant external system. The request is executed asynchronously, as a background operation, and is sent to the external system that’s defined by the external object’s associated external data source.
public static Database.SaveResult updateAsync(SObject sobject)
-
sobject:
Type: SObject
External object record to modify.
Type: Database.SaveResult
Status result for the insert operation. The result corresponds to a record processed by this asynchronous operation and is associated with a unique identifier (asyncLocator). The asyncLocator value is included in the errors array of the result. You can retrieve this identifier with Database.getAsyncLocator(). Retrieve the final result with Database.getAsyncSaveResult().
Initiates requests to update external object data on the relevant external systems. The requests are executed asynchronously, as background operations, and are sent to the external systems that are defined by the external objects’ associated external data sources. Allows referencing a callback class whose processSave method is called for each record after the remote operations are completed.
public static List<Database.SaveResult> updateAsync(List<SObject> sobjects, DataSource.AsyncSaveCallback callback, System.AccessLevel accessLevel)
-
sobjects:
Type: List<SObject> List of external object records to modify.
-
callback:
Type: DataSource.AsyncSaveCallback
The callback object that contains the state in the originating context and an action (the
processSavemethod) that executes after the insert operation is completed. The execution is in system mode regardless of theaccessLevelparameter. Use the action callback to update org data according to the operation’s results. The callback object must extendDataSource.AsyncSaveCallback. -
accessLevel:
Type: System.AccessLevel
(Optional) The accessLevel parameter specifies whether the method runs in system mode (
AccessLevel.SYSTEM_MODE) or user mode (AccessLevel.USER_MODE). In system mode, the object and field-level permissions of the current user are ignored, and the record sharing rules are controlled by the class sharing keywords. In user mode, the object permissions, field-level security, and sharing rules of the current user are enforced. User mode is the default.
Type: List<Database.SaveResult>
Status results for the update operation. Each result corresponds to a record processed by this asynchronous operation and is associated with a unique identifier (asyncLocator). The asyncLocator value is included in the errors array of the result. You can retrieve this identifier with Database.getAsyncLocator(). Retrieve the final result with Database.getAsyncSaveResult().
Initiates a request to update external object data on the relevant external system. The request is executed asynchronously, as a background operation, and is sent to the external system that’s defined by the external object’s associated external data source. Allows referencing a callback class whose processSave method is called after the remote operation is completed.
public static Database.SaveResult updateAsync(SObject sobject, DataSource.AsyncSaveCallback callback, System.AccessLevel accessLevel)
-
sobject:
Type: SObject External object record to modify.
-
callback:
Type: DataSource.AsyncSaveCallback
The callback object that contains the state in the originating context and an action (the
processSavemethod) that executes after the insert operation is completed. The execution is in system mode regardless of theaccessLevelparameter. Use the action callback to update org data according to the operation’s results. The callback object must extendDataSource.AsyncSaveCallback. -
accessLevel:
Type: System.AccessLevel
(Optional) The accessLevel parameter specifies whether the method runs in system mode (
AccessLevel.SYSTEM_MODE) or user mode (AccessLevel.USER_MODE). In system mode, the object and field-level permissions of the current user are ignored, and the record sharing rules are controlled by the class sharing keywords. In user mode, the object permissions, field-level security, and sharing rules of the current user are enforced. User mode is the default.
Type: Database.SaveResult
Status result for the insert operation. The result corresponds to a record processed by this asynchronous operation and is associated with a unique identifier (asyncLocator). The asyncLocator value is included in the errors array of the result. You can retrieve this identifier with Database.getAsyncLocator(). Retrieve the final result with Database.getAsyncSaveResult().
Initiates requests to update external object data on the relevant external systems. The requests are executed asynchronously, as background operations, and are sent to the external systems that are defined by the external objects’ associated external data sources.
public static List<Database.SaveResult> updateAsync(List<SObject> sobjects, System.AccessLevel accessLevel)
-
sobjects:
Type: List<SObject>
List of external object records to modify.
-
accessLevel:
Type: System.AccessLevel
(Optional) The accessLevel parameter specifies whether the method runs in system mode (
AccessLevel.SYSTEM_MODE) or user mode (AccessLevel.USER_MODE). In system mode, the object and field-level permissions of the current user are ignored, and the record sharing rules are controlled by the class sharing keywords. In user mode, the object permissions, field-level security, and sharing rules of the current user are enforced. User mode is the default.
Type: List<Database.SaveResult>
Status results for the update operation. Each result corresponds to a record processed by this asynchronous operation and is associated with a unique identifier (asyncLocator). The asyncLocator value is included in the errors array of the result. You can retrieve this identifier with Database.getAsyncLocator(). Retrieve the final result with Database.getAsyncSaveResult().
Initiates a request to update external object data on the relevant external system. The request is executed asynchronously, as a background operation, and is sent to the external system that’s defined by the external object’s associated external data source.
public static Database.SaveResult updateAsync(SObject sobject, System.AccessLevel accessLevel)
-
sobject:
Type: SObject
External object record to modify.
-
accessLevel:
Type: System.AccessLevel
(Optional) The accessLevel parameter specifies whether the method runs in system mode (
AccessLevel.SYSTEM_MODE) or user mode (AccessLevel.USER_MODE). In system mode, the object and field-level permissions of the current user are ignored, and the record sharing rules are controlled by the class sharing keywords. In user mode, the object permissions, field-level security, and sharing rules of the current user are enforced. User mode is the default.
Type: Database.SaveResult
Status result for the insert operation. The result corresponds to a record processed by this asynchronous operation and is associated with a unique identifier (asyncLocator). The asyncLocator value is included in the errors array of the result. You can retrieve this identifier with Database.getAsyncLocator(). Retrieve the final result with Database.getAsyncSaveResult().
Initiates requests to update external object data on the relevant external systems. The requests are executed synchronously and are sent to the external systems that are defined by the external objects’ associated external data sources. If the Apex transaction contains pending changes, the synchronous operations can’t be completed and throw exceptions.
public static List<Database.SaveResult> updateImmediate(List<SObject> sobjects)
-
sobjects:
Type: List<SObject>
List of external object records to modify.
Type: List<Database.SaveResult>
Status results for the update operation.
The operation allows partial success. If one or more record updates fail, the method doesn’t throw an exception and the remainder of the DML operation can still succeed. The returned SaveResult objects indicate whether the operation was successful. If it wasn’t successful, the objects also return the error code and description.
Initiates a request to update external object data on the relevant external system. The request is executed synchronously and is sent to the external system that’s defined by the external object’s associated external data source. If the Apex transaction contains pending changes, the synchronous operation can’t be completed and throws an exception.
public static Database.SaveResult updateImmediate(SObject sobject)
-
sobject:
Type: SObject
External object record to modify.
Type: Database.SaveResult
Status result for the update operation.
If a record update fails, the method doesn’t throw an exception. The returned SaveResult object indicates whether the operation was successful. If it wasn’t successful, the object returns the error code and description.
Initiates requests to update external object data on the relevant external systems. The requests are executed synchronously and are sent to the external systems that are defined by the external objects’ associated external data sources. If the Apex transaction contains pending changes, the synchronous operations can’t be completed and throw exceptions.
public static List<Database.SaveResult> updateImmediate(List<SObject> sobjects, System.AccessLevel accessLevel)
-
sobjects:
Type: List<SObject>
List of external object records to modify.
-
accessLevel:
Type: System.AccessLevel
(Optional) The accessLevel parameter specifies whether the method runs in system mode (
AccessLevel.SYSTEM_MODE) or user mode (AccessLevel.USER_MODE). In system mode, the object and field-level permissions of the current user are ignored, and the record sharing rules are controlled by the class sharing keywords. In user mode, the object permissions, field-level security, and sharing rules of the current user are enforced. User mode is the default.
Type: List<Database.SaveResult>
Status results for the update operation.
The operation allows partial success. If one or more record updates fail, the method doesn’t throw an exception and the remainder of the DML operation can still succeed. The returned SaveResult objects indicate whether the operation was successful. If it wasn’t successful, the objects also return the error code and description.
Initiates a request to update external object data on the relevant external system. The request is executed synchronously and is sent to the external system that’s defined by the external object’s associated external data source. If the Apex transaction contains pending changes, the synchronous operation can’t be completed and throws an exception.
public static Database.SaveResult updateImmediate(SObject sobject, System.AccessLevel accessLevel)
-
sobject:
Type: SObject
External object record to modify.
-
accessLevel:
Type: System.AccessLevel
(Optional) The accessLevel parameter specifies whether the method runs in system mode (
AccessLevel.SYSTEM_MODE) or user mode (AccessLevel.USER_MODE). In system mode, the object and field-level permissions of the current user are ignored, and the record sharing rules are controlled by the class sharing keywords. In user mode, the object permissions, field-level security, and sharing rules of the current user are enforced. User mode is the default.
Type: Database.SaveResult
Status result for the update operation.
If a record update fails, the method doesn’t throw an exception. The returned SaveResult object indicates whether the operation was successful. If it failed, the object returns the error code and description.