My name is Kanav Khurana and I’m a Senior Solution Architect within Nextview. Recently I have been working more and more with Salesforce flows. The use of Flows can automate multiple processes within the business. Flows have given functional consultants a new superpower: complex business logic – that earlier needed Apex code – can now be automated declaratively. I have recently started using them extensively and would like to share my top 5 learnings to help you embark on the ‘very fulfilling’ journey of building Flows.
Do Not Overstretch
If you have ever written or are going to write a moderately complex flow, you may come across this exception: “Number of iterations exceeded”.
As mentioned in the Salesforce official documentation, the maximum number of executed elements at runtime is 2000. An ‘element’ refers to any block – Query, Screen, Action, Loop, Assignment etc. – that you can drag and drop to the Flow slate from the ‘Toolbox’ -> ‘Elements’ tab on the left.
Let us look at this in the context of a flow:
This a flow that accepts a list of Accounts and loops through them to check for the Industry – and based on the Industry – assigns an Owner. Once the loop is complete, the Account records are updated.
If we run this flow for 200 accounts, then the elements that form the loop portion (highlighted in pink) will count towards 200 * 2 = 400 of the 2000elements. As you can see, this limit of 2000 elements can run out quickly when looping through multiple records/variables. In such cases, it is best to offload the iterative logic to Apex:
This flow consumes 2 elements out of the 2000 irrespective of the number of Accounts being processed.
Connect to external systems
Yes, you heard that right! Until now, functional consultants had to rely on Workflow Outbound Messages to send data from Salesforce to external systems declaratively. However, Outbound messages come with their set of limitations.
A nifty alternative is to use External Services which let you connect to External systems (mostly) declaratively via Flows. Learn more about this feature in this trailhead.
Run flows in System Mode
A recent addition to the Flow arsenal is the ability to run flows in System Mode. This is especially useful for Screen flows which (by default) run in the logged-in User’s context.
It is sometimes necessary to write back-end automation where it is not intended to give associated profile rights to the executing user. In such cases, ‘System mode’ comes to the rescue.
This setting can be enabled via the following steps:
Step 1. Go to the settings in the Flow builder via the gear icon
Step 2. Click ‘Show Advanced’
Step 3. Under ‘How to Run the Flow’, select ‘System Context with Sharing – Enforces Record-Level Access’ and then click ‘Done’.
Make flows test-ready
One of the downsides to writing Screen flows is the inability to write automated Apex tests.
Apex testing has many benefits including reducing manual testing time, reducing regression testing and ensuring product consistency.
However, there is a way to get around this by re-packaging the flow.
Consider a screen flow that calculates the credit rating for an Account based on the Account Industry:
This flow can be broken down into 2 parts – a screen flow with the ‘User Input’ portion – and an autolaunched sub-flow with the ‘Core Logic’:
Part 1: Screen flow
Part 2: Autolaunched sub-flow invoked by the screen flow
In this setup, the subflow created above can be invoked via Apex – by mimicking the inputs of the two Screen elements in Part 1).
The call to the Flow can be put between the Test.startTest() and Test.stopTest() methods of a Test class, followed by asserting the output.
Before Save Flows
Before Save flows, introduced recently, offer a faster alternative to record updates using Process Builder. The way to set up a flow as a ‘Before Save’ flow can be found by editing the ‘Start’ element of the flow:
I hope these pointers were useful! Let me know what you think of the content and please feel free to share other tips and tricks! You can directly contact me on email@example.com. Stay safe!
https://www.nextview.nl/wp-content/uploads/2020/04/Kanav4.png256256nextviewhttps://www.nextview.nl/wp-content/uploads/2018/01/nextview-logo.svgnextview2020-04-10 12:52:032020-04-10 12:57:075 learnings from a Flow state
Nextview Design Thinking Center
Willem Fenengastraat 4C
1096 BN Amsterdam
+31 (0)85 0043065
Nextview Design Thinking Center
High Tech Campus 27
5656 AE Eindhoven
Click on the different category headings to find out more. You can also change some of your preferences. Note that blocking some types of cookies may impact your experience on our websites and the services we are able to offer.
Essential Website Cookies
These cookies are strictly necessary to provide you with services available through our website and to use some of its features.
We provide you with a list of stored cookies on your computer in our domain so you can check what we stored. Due to security reasons we are not able to show or modify cookies from other domains. You can check these in your browser security settings.
Google Analytics Cookies
These cookies collect information that is used either in aggregate form to help us understand how our website is being used or how effective our marketing campaigns are, or to help us customize our website and application for you in order to enhance your experience.
If you do not want that we track your visit to our site you can disable tracking in your browser here:
Other external services
We also use different external services like Google Webfonts, Google Maps, and external Video providers. Since these providers may collect personal data like your IP address we allow you to block them here. Please be aware that this might heavily reduce the functionality and appearance of our site. Changes will take effect once you reload the page.
Google Webfont Settings:
Google Map Settings:
Google reCaptcha Settings:
Vimeo and Youtube video embeds:
The following cookies are also needed - You can choose if you want to allow them: