問題文
A dairy cooperative's trigger on Milk_Delivery__c has to do two things when a delivery is created: default the grade field on the delivery itself, and create a related Quality_Check__c record that points back to the delivery. How should the two concerns be split?
選択肢
- Do both in the after insert context, and update the delivery with an explicit DML statement so that the grade and the related record are written in the same stage of the save order.
- Set the grade in the before insert context and create the related record in the after insert context, where the delivery already has an identifier to point at, because a child needs the parent key.
- Set the grade in the before insert context and create the related record from a queueable job enqueued in the same trigger, because writing to a second object inside the save order is what causes the save procedure to be re-entered and should always be moved out of the transaction.
- Do both in the before insert context, because the platform assigns identifiers before any trigger runs so the quality check can point straight back at the delivery.