問題文
A credit union loads a nightly member file of about 8,000 rows. A handful of rows always fail a validation rule. The operations team needs the good rows saved and a per-row report of what went wrong. Which approach delivers that?
選択肢
- Use the insert statement inside a try and catch block and log the message from the DmlException that comes back to the calling method each time.
- Call Database.insert with the second parameter left at its default and walk the returned SaveResult array, since the array is returned either way and can be read row by row.
- Call Database.insert with the second parameter set to false and walk the returned SaveResult array, reading isSuccess and getErrors for each row to build the report, so that the good rows are committed and each failed row carries its own errors.
- Split the file into 8,000 separate insert statements so that a failure affects only the row it belongs to, and collect the caught exceptions into a list that the operations team reads the next morning.