Pass Objects to Flow via REST with the Serialize/Deserialize Collection Actions

Neil Armstrong, a Flow ace in the Salesforce solution engineering corps, came by with a use case:

I’m working on a Lambda function that can invoke flows via REST. Is there a way to pass in records? The REST API for Flow only accepts strings

As Neil points out,the REST interface only supports string inputs. But you can solve problems like this by passing the object in as a string to the Flow and then using a Flow Action to deserialize (convert) the string to your desired SObject.

This is something that has been available for a long time via custom code, but the recent support that Flow gained for dynamic sobjects makes it possible to package this functionality as an installable pair of actions, provided below.

Serialize SObject To Json

This action takes as input:

inputSObjectThis can be any record. You specify the object type in Flow Builder each time you add an instance of this action to a Flow.

This action outputs a serialized string representing the record. For example, a basic Account generates this JSON:

Deserialize JSON to SObject

This action takes as input:

serializedSObjectStringthis expects a string like the one shown above.

This action outputs a record of the specified type.

Here’s a demo flow that uses both of these. It loads an Account, serializes it to a string, and then converts it back to an account. This flow is available in the package and will run as long as your org has an account with name ‘account1’.

Here’s the configuration of the Deserialization:

You may notice that Account is specified three different times: two visible above and one inside the serialized string. That’s deeply inefficient, but 1) I haven’t quite figured out how to introspect the type that the user selects in the “Object for” field and 2) I don’t have time at the moment to build properly robust json parsing to pull it out of the string. These are left as exercises for people who want to become famous.

One possible use case for this: you can serialize a record and then store it in a string field of another record! And then later on, you can retrieve that string and deserialize it back to a record! I have no idea if that’s useful, but it smells like it could be. Anyone have any other ideas for what one might do with serialization and records in flows?


Unmanaged 1.0.1

View Source


Notify of
Inline Feedbacks
View all comments