The following are the system static methods for Database.
| Name | Arguments | Return Type | Description |
|---|---|---|---|
| convertLead | LeadConvert leadToConvert, Boolean opt_allOrNone |
Database. LeadConvertResult | Converts a lead into an account and contact, as well as (optionally)
an opportunity. The optional opt_allOrNone parameter specifies whether the operation allows partial success. If you specify false for this parameter and a record fails, the remainder of the DML operation can still succeed. This method returns a result object that can be used to verify which records succeeded, which failed, and why. The convertLead method accepts up to 100 LeadConvert objects. Each executed convertLead method counts against the governor limit for DML statements. |
| convertLead | LeadConvert[] leadsToConvert Boolean opt_allOrNone |
Database. LeadConvert Result[] | Converts a list of LeadConvert objects into accounts and contacts,
as well as (optionally) opportunties. The optional opt_allOrNone parameter specifies whether the operation allows partial success. If you specify false for this parameter and a record fails, the remainder of the DML operation can still succeed. This method returns a result object that can be used to verify which records succeeded, which failed, and why. The convertLead method accepts up to 100 LeadConvert objects. Each executed convertLead method counts against the governor limit for DML statements. |
| countQuery | String query | Integer | Returns the number of records that a dynamic SOQL query would
return when executed. For example, String QueryString =
'SELECT count() FROM Account';
Integer i =
Database.countQuery(QueryString);For more information, see Dynamic SOQL. Each executed countQuery method counts against the governor limit for SOQL queries. |
| delete | SObject recordToDelete Boolean opt_allOrNone |
Database. DeleteResult | Deletes an existing sObject record, such as
an individual account or contact, from your organization's data. delete is analogous to the delete() statement in the SOAP API. The optional opt_allOrNone parameter specifies whether the operation allows partial success. If you specify false for this parameter and a record fails, the remainder of the DML operation can still succeed. This method returns a result object that can be used to verify which records succeeded, which failed, and why. Each executed delete method counts against the governor limit for DML statements. |
| delete | SObject[] recordsToDelete Boolean opt_allOrNone |
Database. DeleteResult[] | Deletes a list of existing sObject records, such as individual accounts or contacts, from your
organization’s data. delete is analogous to the delete() statement in the SOAP API. The optional opt_allOrNone parameter specifies whether the operation allows partial success. If you specify false for this parameter and a record fails, the remainder of the DML operation can still succeed. This method returns a result object that can be used to verify which records succeeded, which failed, and why. Each executed delete method counts against the governor limit for DML statements. Example: The following example deletes an account
named 'DotCom': Account[] doomedAccts = [SELECT Id, Name FROM Account WHERE Name = 'DotCom']; Database.DeleteResult[] DR_Dels = Database.delete(doomedAccts); |
| delete | RecordID ID Boolean opt_allOrNone |
Database. DeleteResult | Deletes existing sObject records, such as individual accounts or contacts, from your
organization’s data. delete is analogous to the delete() statement in the SOAP API. The optional opt_allOrNone parameter specifies whether the operation allows partial success. If you specify false for this parameter and a record fails, the remainder of the DML operation can still succeed. This method returns a result object that can be used to verify which records succeeded, which failed, and why. Each executed delete method counts against the governor limit for DML statements. |
| delete | RecordIDs []IDs Boolean opt_allOrNone |
Database. DeleteResult[] | Deletes a list of existing sObject records, such as individual accounts or contacts, from your
organization’s data. delete is analogous to the delete() statement in the SOAP API. The optional opt_allOrNone parameter specifies whether the operation allows partial success. If you specify false for this parameter and a record fails, the remainder of the DML operation can still succeed. This method returns a result object that can be used to verify which records succeeded, which failed, and why. Each executed delete method counts against the governor limit for DML statements. |
| emptyRecycleBin | RecordIds []Ids | Database. EmptyRecycleBin Result[] | Permanently deletes the specified records from the recycle
bin. Note the following:
|
| emptyRecycleBin | sObject sObject | Database. EmptyRecycleBin Result | Permanently deletes the specified sObject from the recycle
bin. Note the following:
|
| emptyRecycleBin | sObjects []listOfSObjects | Database. EmptyRecycleBin Result[] | Permanently deletes the specified sObjects from the recycle
bin. Note the following:
|
| executeBatch | sObject className | ID | Executes the specified class as a batch Apex job. For more information, see Using Batch Apex. |
| executeBatch | sObject className, Integer scope | ID | Executes the specified class as a batch Apex job. The value for scope must be greater than 0. For more information, see Using Batch Apex. |
| getQueryLocator | sObject [] listOfQueries | Database. QueryLocator | Creates a QueryLocator object
used in batch Apex or Visualforce. For more information, see Database.QueryLocator Class, Understanding Apex Managed Sharing, and StandardSetController Class.
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. |
| getQueryLocator | String query | Database. QueryLocator | Creates a QueryLocator object
used in batch Apex or Visualforce. For more information, see Database.QueryLocator Class, Understanding Apex Managed Sharing, and StandardSetController Class.
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. |
| insert | sObject recordToInsert Boolean opt_allOrNone | database.DMLOptions opt_DMLOptions |
Database. SaveResult | Adds an sObject, such as an individual account
or contact, to your organization's data. insert is analogous to the INSERT statement in SQL. The optional opt_allOrNone parameter specifies whether the operation allows partial success. If you specify false for this parameter and a record fails, the remainder of the DML operation can still succeed. This method returns a result object that can be used to verify which records succeeded, which failed, and why. The optional opt_DMLOptions parameter specifies additional data for the transaction, such as assignment rule information or rollback behavior when errors occur during record insertions. 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. |
| insert | sObject [] recordsToInsert Boolean opt_allOrNone | database.DMLOptions opt_DMLOptions |
Database. SaveResult[] | Adds one or more sObjects, such as individual accounts or contacts, to your organization’s
data. insert is analogous to the INSERT statement in SQL. The optional opt_allOrNone parameter specifies whether the operation allows partial success. If you specify false for this parameter and a record fails, the remainder of the DML operation can still succeed. This method returns a result object that can be used to verify which records succeeded, which failed, and why. The optional opt_DMLOptions parameter specifies additional data for the transaction, such as assignment rule information or rollback behavior when errors occur during record insertions. 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: Account a = new Account(name = 'Acme1'); Database.SaveResult[] lsr = Database.insert( new Account[]{a, new Account(Name = 'Acme2')}, false); |
| query | String query | sObject[] | Creates a dynamic SOQL query at runtime. 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 are not supported. For more information, see Dynamic SOQL. Each executed query method counts against the governor limit for SOQL queries. |
| rollback | System.Savepoint sp | Void | 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. Note the following:
For an example, see Transaction Control. |
| setSavepoint | System.Savepoint | 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. Note the following:
For an example, see Transaction Control. |
|
| undelete | sObject recordToUndelete Boolean opt_allOrNone |
Database. UndeleteResult | Restores an existing sObject record, such as
an individual account or contact, from your organization's Recycle
Bin. undelete is analogous to the UNDELETE statement in SQL. The optional opt_allOrNone parameter specifies whether the operation allows partial success. If you specify false for this parameter and a record fails, the remainder of the DML operation can still succeed. This method returns a result object that can be used to verify which records succeeded, which failed, and why. Each executed undelete method counts against the governor limit for DML statements. |
| undelete | sObject [] recordsToUndelete Boolean opt_allOrNone |
Database. UndeleteResult[] | Restores one or more
existing sObject records, such as individual accounts or contacts,
from your organization’s Recycle Bin. undelete is analogous to the UNDELETE statement in SQL. The optional opt_allOrNone parameter specifies whether the operation allows partial success. If you specify false for this parameter and a record fails, the remainder of the DML operation can still succeed. This method returns a result object that can be used to verify which records succeeded, which failed, and why. Each executed undelete method counts against the governor limit for DML statements. Example: The following example restores all
accounts named 'Trump'. The ALL ROWS keyword queries all rows for both top-level and aggregate relationships,
including deleted records and archived activities. Account[] SavedAccts = [SELECT Id, Name FROM Account WHERE Name = 'Trump' ALL ROWS]; Database.UndeleteResult[] UDR_Dels = Database.undelete(SavedAccts); |
| undelete | RecordID ID Boolean opt_allOrNone |
Database. UndeleteResult | Restores an existing sObject record, such as
an individual account or contact, from your organization's Recycle
Bin. undelete is analogous to the UNDELETE statement in SQL. The optional opt_allOrNone parameter specifies whether the operation allows partial success. If you specify false for this parameter and a record fails, the remainder of the DML operation can still succeed. This method returns a result object that can be used to verify which records succeeded, which failed, and why. Each executed undelete method counts against the governor limit for DML statements. |
| undelete | RecordIDs[] ID Boolean opt_allOrNone |
Database. UndeleteResult[] | Restores one or more
existing sObject records, such as individual accounts or contacts,
from your organization’s Recycle Bin. undelete is analogous to the UNDELETE statement in SQL. The optional opt_allOrNone parameter specifies whether the operation allows partial success. If you specify false for this parameter and a record fails, the remainder of the DML operation can still succeed. This method returns a result object that can be used to verify which records succeeded, which failed, and why. Each executed undelete method counts against the governor limit for DML statements. |
| update | sObject recordToUpdate Boolean opt_allOrNone | database.DMLOptions opt_DMLOptions |
Database. SaveResult | Modifies an existing sObject record, such as
an individual account or contact, in your organization's data. update is analogous to the UPDATE statement in SQL. The optional opt_allOrNone parameter specifies whether the operation allows partial success. If you specify false for this parameter and a record fails, the remainder of the DML operation can still succeed. This method returns a result object that can be used to verify which records succeeded, which failed, and why. The optional opt_DMLOptions parameter specifies additional data for the transaction, such as assignment rule information or rollback behavior when errors occur during record insertions. 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. Example: The
following example updates the BillingCity field on a single account. Account a = new Account(Name='SFDC'); insert(a); Account myAcct = [SELECT Id, Name, BillingCity FROM Account WHERE Id = :a.Id]; myAcct.BillingCity = 'San Francisco'; Database.SaveResult SR = Database.update(myAcct); |
| update | sObject [] recordsToUpdate Boolean opt_allOrNone |database.DMLOptions opt_DMLOptions |
Database. SaveResult[] | Modifies one or more existing sObject
records, such as individual accounts or contactsinvoice statements, in your organization’s data. update is analogous to the UPDATE statement in SQL. The optional opt_allOrNone parameter specifies whether the operation allows partial success. If you specify false for this parameter and a record fails, the remainder of the DML operation can still succeed. This method returns a result object that can be used to verify which records succeeded, which failed, and why. The optional opt_DMLOptions parameter specifies additional data for the transaction, such as assignment rule information or rollback behavior when errors occur during record insertions. 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. |
| upsert | sObject recordToUpsert Schema.SObjectField External_ID_Field Boolean opt_allOrNone |
Database. UpsertResult | Creates a new sObject record or updates an existing sObject
record within a single statement, using an optional custom field to determine
the presence of existing objects. The External_ID_Field is of type Schema.SObjectField, that is, a field token. Find the token for the field by using the fields special method. For example, Schema.SObjectField f = Account.Fields.MyExternalId. The optional opt_allOrNone parameter specifies whether the operation allows partial success. If you specify false for this parameter and a record fails, the remainder of the DML operation can still succeed. This method returns a result object that can be used to verify which records succeeded, which failed, and why. 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. |
| upsert | sObject [] recordsToUpsert Schema.SObjectField External_ID_Field Boolean opt_allOrNone |
Database. UpsertResult[] | Cusing an optional custom field to determine
the presence of existing objects. The External_ID_Field is of type Schema.SObjectField, that is, a field token. Find the token for the field by using the fields special method. For example, Schema.SObjectField f = Account.Fields.MyExternalId. The optional opt_allOrNone parameter specifies whether the operation allows partial success. If you specify false for this parameter and a record fails, the remainder of the DML operation can still succeed. This method returns a result object that can be used to verify which records succeeded, which failed, and why. 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. |