function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
João AlmeidaJoão Almeida 

Apex: start flow with record collection input

I'm trying to start a flow that receives a record collection as input.

I have the following code:

List<YB_Dosage_Line__c> parsedDosagelines =(List<YB_Dosage_Line__c>)JSON.deserializeStrict(serializedApplicationRecord,List<YB_Dosage_Line__c>.class);
                Map<String, Object> flowParams = new Map<String, Object>{'dosageLines' => parsedDosagelines};
                Flow.Interview.YB_Dosage_Lines_Process_Related_Generic_Group_and_Product_Family flowInstance = new Flow.Interview.YB_Dosage_Lines_Process_Related_Generic_Group_and_Product_Family(flowParams);

But, it throws the following error:

Malformed JSON: Expected '[' at the beginning of List/Set
Any ideas?
João AlmeidaJoão Almeida
Actually, I found the problem: "serializedApplicationRecord" is the wrong variable, this one doesn't contain a list. But, its interesting that the serializeStrict doesn't fail...
Prateek Prasoon 25Prateek Prasoon 25
The error message you're encountering indicates that the JSON string serializedApplicationRecord is not valid JSON because it does not start with a square bracket '[' as expected for a List/Set.
To resolve this issue, you need to ensure that the JSON string you are trying to deserialize is properly formatted and begins with a '[' to indicate the start of a list. Here's an example of a valid JSON string representing a list of YB_Dosage_Line__c objects:
      [  {    "field1": "value1",    "field2": "value2"  },  {    "field1": "value3",    "field2":"value4" }]

Make sure serializedApplicationRecord contains a correctly formatted JSON array of YB_Dosage_Line__c objects.

If you find my answer helpful, please mark it as the best answer. thanks!