Are you looking for a CRM solution that grows with your organization and is easy to adapt, without needing a developer for every change? Within Salesforce, Flow seems to be the low-code automation tool that makes this possible. With Flow you can automate processes and quickly respond to changing needs. Yet Flow is not always the best choice: for complex business logic and advanced automation, Apex, Salesforce's programming language, often offers more possibilities. 

In this article, we'll try to explain to you as best we can when it's best to choose Salesforce Flow and when to choose Apex. 

First things first 

Starting with the basics, we first provide an introduction to Salesforce Flow and Apex:

Salesforce Flow 

Salesforce Flow is an automation tool that allows admins to build applications that collect, update and edit data based on specific conditions. Salesforce Flow is a No-code / Low-code solution. This refers to a development approach that allows users to create applications and automate processes without writing traditional code. Instead, it uses intuitive visual interfaces, drag-and-drop functionality and pre-built components. 

Example Salesforce Flow 

Apex 

Apex is Salesforce's proprietary programming language, designed specifically to enable complex logic and customization within the Salesforce platform. It is also called a sister language to Java because of its Java-like syntax, concepts and functions. Apex is primarily used when certain automations are not possible in standard flows. 

Choose the right tool for the right use case  

When automating processes in Salesforce, it is crucial to choose the right tool. Always look first to see if Salesforce offers standard functionality for the automation you want to create. If a standard functionality exists, use it. The big advantage of this? Salesforce takes care of updates, maintenance and security itself. When using Flow or Apex, that responsibility lies with yourself. If no standard Salesforce functionality exists, choose to build the automation with Flow. 

So when do you choose Apex? If your process is more complex than what Flow can handle, Apex is the logical step. Apex offers maximum flexibility, but also requires more management and documentation. 

Let your end goal be leading 

The choice between Flow and Apex depends on what you want to achieve. A well-maintained Flow is often sufficient, but as soon as a Flow becomes too complicated, switching to Apex is wise. As in the image below: here you see a flow that has become cluttered. It still works, but it's hard to know what happens when you make one adjustment. 

Example overly complex Flow

Misconceptions about cost and speed 

Because Flow is a No-Code / Low-Code solution, many people think it is automatically cheaper and faster than programming with Apex. It seems like a logical thought because admins without programming knowledge can make modifications themselves. 

But this is not always the case. Both options have their own complexity and maintenance requirements. A simple Flow can be fast, but once processes become complicated, building and maintaining can actually become time-consuming and costly. Apex can be more efficient and reliable in some cases, depending on the use case. 

Rules of thumb 

  1. First, investigate whether there is a standard functionality for the automation you want to build. If there isn't then Flow is your first next choice.

Use Flow when: 

  1. There is no standard Salesforce process for it; 
  2. The process is simple; 
  3. The user should be able to click through; 
  4. It involves one or a few records; 
  5. Admins should be able to make adjustments themselves. 

Use Apex when: 

  1. A lot of data is being worked on at once; 
  2. There is computational work to be done based on multiple tables/rules; 
  3. There is an external linkage; 
  4. There is a need for a good way to catch mistakes and handle them neatly.... 

Use Flow + Apex when:

  1. User-friendly Flow is desired, but the computational logic is too heavy for Flow; 
  2. When Flow can call an Apex class. 

Document your choices 

Do you recognize that you no longer know which function is for what? That a change in A causes B to collapse? This is often the result of insufficient documentation and a lack of structure in your choices. Whatever choice you don't make, always document why you chose a particular solution and what the impact is. 

Conclusion 

Thus, the choice between Flow and Apex depends on the complexity of the logic. When a Flow becomes too complex, it is difficult to manage, while the same logic can be managed more efficiently with Apex.  

Prior to implementation, it is important to design your process and assess whether there is a standard Salesforce process for this and whether it requires frequent adjustments. If this is the case, Flow is preferred. However, if the requirements include complex logic or large amounts of data, Apex is usually the better option. 

Need help building automations in Flow or Apex? Our consultants are always ready to answer your questions.