My scenario

I have an apex class that extends RestResource.Base

In this class I insert both the parent and child record at the same time

List<SObject> recordsToInsert = new List<SObject>();
List<Database.SaveResult> saveResults = Database.insert(recordsToInsert, false);

expected request body:

    "fullName" : "John Doe",
    "email" : "[email protected]",
    "childRecords" : [
            "question" : "what do you eat?",
            "answer" : "rice"
            "question" : "do you like color red?",
            "answer" : "yes"
    ] }

I then have a flow that runs After Save on Opportunity Records wherein I get child record/s and send the customer a customized email based on the child record details.

My problem is that by the time the flow is run, the child records aren't picked up.

What I tried: Set the flow Trigger Order = 100; create trigger on parent record and add wait for 30 seconds before doing the operation.


1 Answer 1


The reason for your issue is the following:

  • The recordsToInsert variable contains an Opportunity and 0..n Child Records.
  • The insert operation will insert the Opportunity first and then initiate the Save operation as defined in Triggers and Order of Execution.
    • This in turn will initiate your Flow
    • Which is why the flow doesn't find the children

The solution to this is to define a custom field (Roll Up Summary or DLRS if not master-detail) in the Opportunity that counts the number of children recs. When that count equals the expected number of children records (a separate custom field on Opportunity), then adjust your Flow's entry condition

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .