DML Flashcards
1
Q
What is DML?
A
- DML stands for Data Manipulation Language
- it’s what we use to perform any create, update, or delete operations on records within our org
- DML statements can be included inline in Apex code
2
Q
What are the six DML statements?
A
- insert - creates a new record and inserts it into the database
- update - update an existing record
- upsert - insert new record and update any existing ones (insert + update)
- delete - soft delte record (send to recycle bin)
- merge - merge multiple records into one (delete + update)
- undelete - restore record from Org’s recycle bin
3
Q
What do Database Classes do?
A
- they can manipulate records through methods of the Database class
- the Database class methods for DMl operations each return a single Result object or a list of result of objects
just like DML statements!
4
Q
What Database class methods for DML operations do we have?
A
- Database.insert(),
- Database.update(),
- Database.upsert(),
- Database.delete(),
- Database.merge(),
- Database.undelete(),
- Database.convertLead()
5
Q
What is the allOrNone parameter?
A
It is an additional optional paramter available to all of the Database class methods
- this parameter takes a Boolean value and defaults to true
- this means is that DML operations using Database class methods are by default all-or-none operations - i.e. if the operation fails on a single record in a collection, the operation will fail for the entirety the collection, no matter the success or failure of any other record in the collection
- if we give a false value to the allOrNone parameter, then we can implement partial completion functionality, so any error-free records will have their changes committed to the database and only those records that have errors will fail the operation
- DML operations that use DML statements are always all-or-none operations and we can’t change this
6
Q
What are the methods of Transaction Control we have in the Database class?
A
- we can wrap these methods around logic that alters records in our org and then return the database to the state that it was in before those changes were made if we need to
- Database.setSavepoint() returns an instance of the Savepoint class
- we pass this Savepoint instance as an argument to Database.rollback()
7
Q
How do we avoid vornor limits on the number of DML operations?
A
we’ll want to operate on collections of records, rather than individual records
note. keep DML operations outside of loops