top of page

How to use Apex-Defined Types to store and manipulate complex data structures in Flow.



Apex-defined properties change data management in Salesforce Flows. Thanks to recent updates, Flow Elements now easily modifies custom containers, simplifying data processing without extensive coding. Read the full blog and explore how Apex-defined types increase operational efficiency and seamless integration of external systems.


Use Apex-Defined Data Type Collection Variables with Operators in Assignment and Decision Elements:


Data types defined by Apex are like custom containers that help Salesforce flow to deal with complex issues. Such data structures are often needed when dealing with web services or when you have complex data to optimize.


Now, thanks to a recent update, lots of flows can be built on these custom containers. The "Assignment" and "Decision" elements in flows can now handle these custom containers more efficiently. In the past, they were a bit limited. These stereotypes can only be compared because of the similarities. But now, they can do even more. All types of functions can be used, as in the case of continuous variables.


So, if you have some good data structures working in your Salesforce flow, you're in luck. Now you can change them in every way, making your flow more powerful and intuitive than ever!


Where: This change applies to Lightning Experience and Salesforce Classic in Enterprise, Performance, Unlimited, and Developer editions.


Why: For example, a flow uses an Apex-defined collection variable to store a list of car registrations from a system outside of Salesforce. Now you can use a Decision element to check whether a car registration already exists in the list of registrations from the external system.



If the registration isn’t already in the list of registrations, you can add it to the list using an Assignment element.



Manipulate Complex Internet Data in Flows Without Code Using Apex-Defined Data Types: 


Flows are now able to handle the complex data that often comes from web services. Topic-defined variables allow you to create unique variables in a flow. This change helps you process JSON data directly from web calls. It's the easiest way to manage data in your Salesforce workflow!


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 objects pipeline, it's much easier to process complex JSON from web calls without writing Apex code. This is how it works:


Define an Apex Class: A developer creates an Apex class to help convert web data into a format understandable by Flow.


No additional code required: Flow can replace data that has been completely transformed using point-and-click tools, eliminating the need for additional code.


Perfect for external web content: This feature is ideal for integrating external web content streams accessed via Mulesoft and REST APIs. This facilitates integration and data manipulation.


Handle unprocessed data types:  If a data type is not directly supported by the flow, it can be moved to an Aura component. You can then use Apex to get around it.


Consider a car dealership screen flow that allows customers to search for inventory data stored elsewhere. Here's how you can use Apex-defined features:


The vendor creates an apex class that defines the structure of the "Car" object.

They create a screen flow with two Apex-defined variables representing vehicle data.

A stream passes these changes through its network, an Apex process, and an Aura component for smooth data processing.

In short, the features defined by Apex make it easier to work with complex data streams, especially when connecting Salesforce to external systems such as databases.


The Car Apex class defines fields, such as contact, registration, and model. The @AuraEnabled annotation is required for each field you want to expose to Flow.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}.



An Aura component defines the DisplayCar screen component with the CarResult attribute. The attribute’s type is the Car Apex class that defines the Apex-defined data type. The screen component displays the attribute’s value.


<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 its value during runtime.




Here are some important things to remember when using Apex-defined data types.


Supported Data Types: Apex classes support a wide variety of data types, including Boolean, Integer, Long, Decimal, Double, Date, DateTime, and String. You can also use single values ​​and lists for each data type. If you need to represent complex web objects, you can combine multiple Apex classes.


Performance considerations: In organizations with over 200 @AuraEnabled vertex classes, the first time you open an element or resource window, it may take some time to load. This is something business owners should keep in mind.


User license for streams calling Apex: As of Summer '19, when a stream calls Apex code, the user who created the stream must have a corresponding Apex class in his or her profile or permission set to ensure that the stream's apex logic can be executed. Without any issues.


With this in mind, you can effectively use Apex-defined data types in your Salesforce environment while maintaining optimal performance and user permissions.

Apex-defined types have improved data management in Salesforce Flows by providing more efficient tools for managing complex configurations. These updates have transformed Salesforce operations by streamlining web data processing and integrating seamlessly with external systems.


Using Apex-defined types, users can easily navigate complex data views with minimal coding. The ability to execute complex JSON from web calls without requiring additional Apex code improves operational efficiency and integration capabilities. Companies that adopt these advancements continue to lead and unlock growth and innovation in the use of Salesforce. Get a 30-minute free consultation about Salesforce implementation services.

288 views0 comments

Comments


bottom of page