Manipulate Complex Internet Data in Flows Without Code Using Apex-Defined Data Types
Where: This change applies to Lightning Experience and Salesforce Classic in Enterprise, Performance, Unlimited, and Developer editions.
Why: Previously, Apex Actions and External Service Registrations were used to manipulate web data, but that data had to be in the form of primitive data types like strings and numbers. Enterprise data from the web retrieved via integration solutions like Mulesoft is rarely composed solely or primarily of primitive data types.
With the new Apex-defined resources in flows, a flow no longer needs to use Apex code to process complex JSON returned from web calls. A developer defines an Apex class to serve as a pattern for automatic conversion from web to a flow, and then full manipulation of the resulting objects can be carried out in a flow using declarative approaches and no additional code. This solution is particularly useful for connecting flows to rich external web objects accessed via Mulesoft and REST calls. If a data type is not supported, flows can pass the value to an Aura component and you can use Apex to operate on it.
For example, a car dealership has a screen flow that lets customers search the dealership’s inventory data, which is stored in another database. The dealership creates an Apex class in their org to define the Car data type. Then, the dealership creates a screen flow that includes two Apex-defined variables. The flow passes the variables between the flow, an Apex action, and an Aura component.
public class Car {
@AuraEnabled
public Contact contact {get;set;}
@AuraEnabled
public String registration {get;set;}
@AuraEnabled
public String model {get;set;}
}
The entire Car object, including its nested contact, is stored in an Apex defined variable {!Car_Inventory}.
A flow screen collects an input value for the car model and stores it in the {!Car_Model} text variable. The text variable is assigned to the {!Car_Inventory.model} Apex-defined variable.
global class FindCars {
@InvocableMethod(label='Find Cars')
//Perform logic to return car results based on the model.
Return results;
}
The Find Cars Apex action results are stored in the flow as the {!Car_Result} Apex-defined variable.
<aura:component implements="lightning:availableForFlowScreens" access="global">
<aura:attribute name="CarResult" type="Car" access="global"/>
<!--Add some styling to the component and display the attribute’s value-->
<div style=”box”>
<p>{!v.CarResult.model} : {!v.CarResult.buildDate}</p>
</div>
</aura:component>
In the DisplayCar screen component, the Car Result attribute contains the {!CarResult} Apex-defined variable and displays it’s value during runtime.
- Supported data types in an Apex class are Boolean, Integer, Long, Decimal, Double, Date, DateTime, and String. Single values as well as lists are supported for each data type. Multiple Apex classes can be combined to represent complex web objects.
- The first time you open an element or resource window in an org with over 200 Apex classes that have the @AuraEnabled annotation, the window may take a while to load.
- As of Summer ‘19, if a flow invokes Apex, the running user must have the corresponding Apex class assignment in their profile or permission set.

