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
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What are the six DML statements?

A
  1. insert - creates a new record and inserts it into the database
  2. update - update an existing record
  3. upsert - insert new record and update any existing ones (insert + update)
  4. delete - soft delte record (send to recycle bin)
  5. merge - merge multiple records into one (delete + update)
  6. undelete - restore record from Org’s recycle bin
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
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!

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What Database class methods for DML operations do we have?

A
  1. Database.insert(),
  2. Database.update(),
  3. Database.upsert(),
  4. Database.delete(),
  5. Database.merge(),
  6. Database.undelete(),
  7. Database.convertLead()
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
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
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
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()
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly