-
Notifications
You must be signed in to change notification settings - Fork 519
DMLRecipes
Demonstrates various ways of making Data Manipulation Language (DML) calls. Note that this class demonstrates both Database.* methods as well as DML Keywords.
Group Data Recipes
Demonstrates how to use the insert keyword to persist a net-new record to the database in system mode
| Param | Description |
|---|---|
name |
name passed through to the name of the created account |
DMLRecipes.insertAccountViaInsertKeywordInSystemMode('Hello');Demonstrates how to use the insert keyword to persist a net-new record to the database in user mode
| Param | Description |
|---|---|
name |
name passed through to the name of the created account |
DMLRecipes.insertAccountViaInsertKeywordInUserMode('Hello');public static insertAccountsViaDatabaseMethod(String name, Boolean allOrNothing, System accessLevel)
Demonstrates how to use the Database.insert() method to persist a net-new record to the database.
| Param | Description |
|---|---|
name |
name Passed through to the account created |
allOrNothing |
allOrNothing determines whether or not all accounts to be inserted must insert successfully |
DMLRecipes.insertAccountsViaDatabaseMethod('Hello', false, AccessLevel.USER_MODE);Demonstrates the use of the upsert keyword to either insert or update a record in system mode
| Param | Description |
|---|---|
acct |
account to upsert |
| Type | Description |
|---|---|
| Account | Account |
DMLRecipes.upsertAccountViaUpsertKeywordInSystemMode(new Account(name='Hello World'));Demonstrates the use of the upsert keyword to either insert or update a record in user mode
| Param | Description |
|---|---|
acct |
account to upsert |
| Type | Description |
|---|---|
| Account | Account |
DMLRecipes.upsertAccountViaUpsertKeywordInUserMode(new Account(name='Hello World'));public static upsertAccountViaDatabaseMethod(Account acct, Boolean allOrNothing, System accessLevel)
Upserts an account with a potential of all or nothing, using the Database.upsert method
| Param | Description |
|---|---|
acct |
The account object to upsert |
allOrNothing |
all or nothing flag |
| Type | Description |
|---|---|
| Database | UpsertResult |
DMLRecipes.upsertAccountViaDatabaseMethod(
new Account(name='Hello World'), false, AccessLevel.USER_MODE);Demonstrates how to Update a list of accounts via the Update DML keyword in System Mode
| Param | Description |
|---|---|
accts |
List of accounts to update |
| Type | Description |
|---|---|
| List | List |
Account acct = new Account(name='Hello World');
insert acct;
DMLRecipes.updateAcccountViaKeywordInSystemMode(acct);Demonstrates how to Update a list of accounts via the Update DML keyword
| Param | Description |
|---|---|
accts |
List of accounts to update |
| Type | Description |
|---|---|
| List | List |
Account acct = new Account(name='Hello World');
insert acct;
DMLRecipes.updateAcccountViaKeyword(acct);Demonstrates how to update a list of accounts via the Database.update() method
| Param | Description |
|---|---|
accts |
list of accounts to update |
| Type | Description |
|---|---|
| List | List |
List<Account> accounts = new List<Account>{new Account(name = 'Hello World')};
insert accounts;
List<Account> results = DMLRecipes.updateAccountViaDatabaseMethod(accounts, AccessLevel.USER_MODE);
System.debug(results);Deletes a list of accounts via the delete DML keyword
| Param | Description |
|---|---|
accts |
list of accounts to delete in system mode |
List<Account> accounts = new List<Account>{new Account(name = 'Hello World')};
insert accounts;
DMLRecipes.deleteAccountViaKeywordInSystemMode(accounts);Deletes a list of accounts via the delete DML keyword
| Param | Description |
|---|---|
accts |
list of accounts to delete in user mode |
List<Account> accounts = new List<Account>{new Account(name = 'Hello World')};
insert accounts;
DMLRecipes.deleteAccountViaKeywordInUserMode(accounts);Deletes a list of accounts via the Database.delete method
| Param | Description |
|---|---|
accts |
List of Accounts to delete |
List<Account> accounts = new List<Account>{new Account(name = 'Hello World')};
insert accounts in user mode;
DMLRecipes.deleteAccountViaDatabaseMethod(accounts, AccessLevel.USER_MODE);Undeletes a list of accounts via the undelete DML keyword
| Param | Description |
|---|---|
accts |
List of accounts to undelete in user mode |
| Type | Description |
|---|---|
| List | List |
List<Account> accounts = new List<Account>{new Account(name = 'Hello World')};
insert accounts;
delete accounts;
List<Account> results = DMLRecipes.undeleteAccountViaKeywordInSystemMode(accounts);
System.debug(results);Undeletes a list of accounts via the undelete DML keyword
| Param | Description |
|---|---|
accts |
List of accounts to undelete in user mode |
| Type | Description |
|---|---|
| List | List |
List<Account> accounts = new List<Account>{new Account(name = 'Hello World')};
insert accounts;
delete accounts;
List<Account> results = DMLRecipes.undeleteAccountViaKeywordInUserMode(accounts);
System.debug(results);undeletes a list of accounts via the Database.undelete method.
| Param | Description |
|---|---|
accts |
list of accounts to undelete |
| Type | Description |
|---|---|
| List | List |
List<Account> accounts = new List<Account>{new Account(name = 'Hello World')};
insert accounts;
delete accounts;
List<Account> results = DMLRecipes.undeleteAccountViaDatabaseMethod(accounts, AccessLevel.USER_MODE);
System.debug(results);This exception is for throwing a custom exception to highlight how negative tests operate.
Inheritance
CustomDMLException