nerdexam
Salesforce

PDII · Question #291

A business requires that every parent record must have a child record. A developer writes an Apex method with two DML statements to insert a parent record and a child record. A validation rule…

The correct answer is B. Set a database savepoint to rollback if there are errors. See the full explanation below for the reasoning.

Question

A business requires that every parent record must have a child record. A developer writes an Apex method with two DML statements to insert a parent record and a child record. A validation rule blocks child records from being created. The method uses a try/catch block to handle the DML exception. What should the developer do to ensure the parent always has a child record?

Options

  • AUse addError() on the parent record if an error occurs on the child record.
  • BSet a database savepoint to rollback if there are errors.
  • CUse Database.insert() and set the allOrNone parameter to true.
  • DDelete the parent record in the catch statement when an error occurs on the child record DML

How the community answered

(35 responses)
  • A
    9% (3)
  • B
    71% (25)
  • C
    17% (6)
  • D
    3% (1)

Community Discussion

No community discussion yet for this question.

Full PDII Practice