Flow Elements

 

        • A brief overview of the three different types of Flow Elements and what they are used for.
            • Interaction
            • Logic
            • Data

  • Interactions

      • Interactions are ways for your users to use the flow (screens), methods to call other flows (sub-flows) or actions which can include quick actions and Apex code.

Screen Element


A Screen Element allows the user to enter data, make selections etc. It can display fields from records stored in Salesforce and prompt the user to add to or update the records. 

Screens can only be added to interactive flows like the Screen Flow type.

None of the triggered flows or the auto launched flows can have screens as they all operate in the background when something triggers them (but not a user action).

There are a large number of components that can be added to a screen (some are shown in the picture below).



Action Element



Actions allow the flow to call other code like Apex Code or Quick Actions.


Apex Action

Calls one of your custom Apex classes. Apex classes are available as Apex actions only if one of the methods is annotated with @InvocableMethod.


Other Categories
There are a number of categories shown on the left below from which you can choose or select "All" to search through all of them.


There are two actions in the Users category:


There are a number of Task actions:


You can Post to Chatter with the Messaging actions:


You can send a simple email in the Email category:


In Approvals, you can submit a record for approval.




Subflow Element



The sub-flow Element allows you to break your automation project into small pieces.

This has many advantages:

  • You can build your flow piece by piece (sub-flow by sub-flow)
  • It is easier to debug the flows
  • Understanding the whole flow is much easier when broken into smaller parts
  • You can re-use some common sub-flows in other flows.

The process of creating a sub-flow is no different to creating a normal flow.

It is a good idea to have a naming convention that indicates which flows are sub-flows and which one is the main flow.

For example:

  • Flow1   (main flow)
    • Flow1A  (sub-flow)
    • Flow1B  (sub-flow)
    • Flow1C  (sub-flow)

Or in this example (the Config-Main flow):

  • Config-Main  (main flow)
    • Config-Order  (sub-flow)
    • Config-Branding  (sub-flow)
    • Config-Logistics  (sub-flow)
    • etc

In the main flow example above there is a screen to get the user selection and a decision element to decide which sub-flow to call.

For triggered flows (without user screen inputs) you can still call a sub-flow based on logic within the flow or record values.


Logic

    • Logic elements allow you to make choices about what you want to do next in your flow.

Assignment Element


The Assignment Element allows you to set values in variables, collection variables, record variables, record collection variables, and global variables.

There are three parts to this assignment process:

  1. The variable you wish to change
  2. The operator
  3. The value you want to assign

The operator values change depending on the data type. 

For a simple number variable, the operator values are:


With a Record Collection (a collection of contact records) the operators are different:



Common Uses of Assignments

If you want to update a field in a record, you would use an assignment element to set the value you want.

The type of field could be text, numbers, dates, checkboxes, picklists etc.

Assignments are commonly used when reading records in a loop, you can decide if the record meets your criteria and assign (add) it to a collection variable for later creating, updating or even deleting the records.


Decision Element



With a Decision element, we can evaluate a set of conditions, and route users through the flow based on the outcomes of those conditions. This element performs the equivalent of an if-then statement.


Multiple conditions (outcomes) can be used in the decision and this creates branches in the flow.




When a flow executes a Decision element, it evaluates each decision outcome in order.

For the first outcome whose conditions are met, the flow takes the associated path.

If no outcome’s conditions are met, the flow takes the path for the default outcome.


Pause Element


Pause element can stop the flow and make it wait until a specified time occurs or when the flow interview receives a platform event message.

Note: A Flow Interview is the execution of a flow. As many users may run the same flow, each time a user launches the flow this is known as a flow interview.

Pause Elements can only be added to autolaunched flows, you cannot add them to screen flows.

Examples:

Pause the flow until a record changes:

 

Pause until multiple resume events occur:

This flow has two events, one that triggers two weeks before a contract expiry date and a second one week before.



Loop Element


The Loop element is used to cycle through items in a collection variable and perform some processing.

The Collection Variable is a variable that contains a number of things they may be a number of email addresses or a number of records (for example).

You can process the items inside the loop using assignment elements to update field values.

Once you have completed this, the next item in the loop is processed and this continues until the last item is processed. The loop then terminates and the flow continues at the next element.

Normally you would write these new values as part of an Update Record or Create Record (or delete) after the loop is finished.

It is important NOT to do the Update Records or Create Records (or delete) inside the loop.

Doing so is bad practice as it can cause your flow to exceed Salesforce Governor limits.



Sample Flow That Loops Through a Collection

Here is a Flow that starts from the current Account record and checks if all related Contacts have an address.
I
f not, it will assign the Account address to these Contacts.

At the end, the contacts without addresses will be updated.



Collection Sort Element

This is a new element introduced with the Spring 22 release of Salesforce.

The collection sort allows you to sort the items in a collection PLUS allows you to limit the number of remaining items.

For example: if you want to sort the records and only keep the last three records that have been updated, you could sort by the last modified date (descending) and keep only the last 3 records.

 



Collection Filter Element

This is a new element introduced with the Spring 22 release of Salesforce.

This element allows you to filter the records in a collection variable, leaving only those items that meet the filter criteria, in the new collection. The original collection is left untouched.

For example: Here the contact records in a collection are filtered to ensure that only records that have not been deleted are retained in the new collection.

Note: A new collection is automatically created for this filtered list.


No comments: