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
Jeremy HendyJeremy Hendy 

Enhanced External Services - can't directly access sub-object in Flow Action

I'm using Flow with Enhanced External Services to bring data in from an external API with a nested object structure including an array of items.

The 200 response from my API returns a top level object called "data" which includes a couple of numeric variables, and then an array object called "items".

I want to loop through the data.items sub-array, so I created a Collection variable of Apex Class FolderListAPI_data_items to hold that array of values.

Flow throws an error  "FlowApexObject cannot be cast to class common.apex.runtime.SObjectRow" error if you try to assign a the Collection Variable to the item array directly from the 200 output of the Action block.

{CollectionVariableDataItems} = {!}

It appears to work only if you first create a Flow Variable for your top level Apex Class, assign that to the 200 output of the API Action, and then assign the Collection variable from that intermediate top level Apex Class variable. 

{ApexClassVariableTopLevel} = {!GetFoldersAPIAction.200}
{CollectionVariableDataItems} = {!}

This doesn't make a lot of sense to me, but there you go.
John CottonJohn Cotton
Thanks for posting this, you unblocked this same issue for me. It's unintuitive, and not well documented. Arrays of Objects are an incredibly simple and common API pattern. The inability to directly access the response items is a little clunky.
Jeremy HendyJeremy Hendy
I've given up on Enhanced External Services altogether, and ended up going back to writing the API calls & handler directly in Apex. Then calling those invocable methods from the Flow (as an Apex Action).  There were simply too many limitations with External Services when using a  "real world" API, with large nested arrays of results.  For example, I would hit the Apex CPU time limit - which appeared to be purely down to internal heap allocation issues; from the logs it looked like each row in each of the items was being copied from Apex-land to Lightning-land, and with nested arrays that ended up blowing the CPU limit of 10 seconds per call. 

So I think Enhanced External Services is only useful if you have a pretty simplistic external API, and don't want to bring back large arrays of results. 

I also figured out (not well documented anywhere) that execution time of your Flow seems to massively slow in Debug mode if you've got loops - or if you happen to have a Developer Console open in another window.  I couldn't figure out why my flow seemed to take 1 minute for the first loop, 2 minutes for the second loop iteration, 3 minutes for the third, etc, etc - it was because I was using Debug mode.