{"id":3283,"date":"2022-05-04T09:50:40","date_gmt":"2022-05-04T09:50:40","guid":{"rendered":"https:\/\/www.bluewavegroup.eu\/?p=3283"},"modified":"2023-01-17T13:17:44","modified_gmt":"2023-01-17T13:17:44","slug":"apex-v-flow-in-2022","status":"publish","type":"post","link":"https:\/\/bluewavecx.com\/ie\/blog\/apex-v-flow-in-2022\/","title":{"rendered":"Match Fight: Apex v Flow. Who Wins in 2022?"},"content":{"rendered":"<div class=\"wpb-content-wrapper\" id=\"wpb-content-root\"><p>[vc_row full_width=&#8221;stretch_row_content&#8221;][vc_column]<aside class=\"ibsImageWrapper\">\n                            <span class=\"ibsImgBanner\">\n\t\t\t\t\t\t\t\t<img decoding=\"async\" srcset=\"https:\/\/bluewavecx.com\/ie\/wp-content\/uploads\/sites\/2\/2022\/05\/18-700x394.png 600w,https:\/\/bluewavecx.com\/ie\/wp-content\/uploads\/sites\/2\/2022\/05\/18-1024x576.png 768w,https:\/\/bluewavecx.com\/ie\/wp-content\/uploads\/sites\/2\/2022\/05\/18.png 1425w\" src=\"https:\/\/bluewavecx.com\/ie\/wp-content\/uploads\/sites\/2\/2022\/05\/18.png\" alt=\"banner image\" sizes=\"(min-width: 1425px) 1425px, (min-width: 1188px) 1188px, (min-width: 768px) 768px, (min-width: 600px) 600px\">\n                            <\/span>\n                     <\/aside>[\/vc_column][\/vc_row][vc_row][vc_column][vc_column_text]<\/p>\r\n<p class=\"has-medium-font-size wp-block-paragraph\">A Retrospective on using Apex or Flow to solve for the Same Business Scenario in Salesforce.<\/p>\r\n\r\n<p>Author:\u00a0<a href=\"https:\/\/www.linkedin.com\/in\/ismail-basser-96354a140\/\" target=\"_blank\" rel=\"noreferrer noopener\">Ismail Basser, Salesforce Consultant<\/a>\u00a0at Bluewave Technology<\/p>\r\n<p class=\"wp-block-paragraph\">\u00a0<\/p>\r\n<hr class=\"wp-block-separator has-css-opacity is-style-wide\" \/>\r\n<p>\u00a0<\/p>\r\n\r\n<div class=\"toc\">\r\n<p>tab { margin-left: 20px; }<br \/>Table of Contents<\/p>\r\n<ol id=\"toc\">\r\n<li><a href=\"#anchor-1\">Introduction<\/a><\/li>\r\n<li><a href=\"#anchor-2\">The Scenario<\/a><\/li>\r\n<li><a href=\"#anchor-3\">Delivering a Flow Solution<\/a><\/li>\r\n<li><a href=\"#anchor-4\">Getting Started<\/a><\/li>\r\n<li><a href=\"#anchor-5\">Node 1\/4 The Get Records Element<\/a><\/li>\r\n<li><a href=\"#anchor-6\">Node 2\/4 The Decision Element<\/a><\/li>\r\n<li><a href=\"#anchor-7\">Node 3\/4 The &#8216;Reports To&#8217; Assignment Element<\/a><\/li>\r\n<li><a href=\"#anchor-8\">Node 4\/4: The &#8216;Level&#8217; Assignment Element<\/a><\/li>\r\n<li><a href=\"#anchor-10\">Delivering an Apex Solution<\/a><\/li>\r\n<li><a href=\"#anchor-11\">The Trigger<\/a><\/li>\r\n<li><a href=\"#anchor-12\">The Class<\/a><\/li>\r\n<li><a href=\"#anchor-13\">The Unit Tests<\/a><\/li>\r\n<li><a href=\"#anchor-14\">Conclusion<\/a><\/li>\r\n<\/ol>\r\n<\/div>\r\n\r\n<p>&nbsp;<\/p>\r\n\r\n<p class=\"wp-block-paragraph\">\u00a0<\/p>\r\n\r\n<h3 class=\"wp-block-heading\" id=\"anchor-1\">Introduction<\/h3>\r\n\r\n<p>Coinciding with Dreamforce 2021, <a href=\"https:\/\/admin.salesforce.com\/blog\/2021\/go-with-the-flow-whats-happening-with-workflow-rules-and-process-builder\" target=\"_blank\" rel=\"noreferrer noopener\">Salesforce announced the planned retirement of both Process Builder and Workflow Rules<\/a>. As a replacement, Flow is the sole declarative option for all platform automation in the future. Subsequently, at TrailblazerDX 2022, there were a whopping <a href=\"https:\/\/reg.salesforce.com\/flow\/plus\/trailblazerdx22\/sessioncatalog\/page\/sessioncatalog?search=flow\" target=\"_blank\" rel=\"noreferrer noopener\">17 sessions<\/a> dedicated to Flow, encouraging Salesforce practitioners to devote time to upskilling on this toolset. With Flow becoming more feature rich, its application also extends to scenarios previously reserved only for Apex. In this post, we will examine Flow against Apex for the same business scenario in order to draw some conclusions about the pros and cons of each option and where the line is in 2022.<\/p>\r\n\r\n<p>&nbsp;<\/p>\r\n\r\n<p class=\"wp-block-paragraph\">\u00a0<\/p>\r\n\r\n<h3 class=\"wp-block-heading\" id=\"anchor-2\">The Scenario<\/h3>\r\n\r\n<p>A customer is already keeping track of their accounts and contacts in Salesforce. And they have a custom picklist, Level__c, on the contact to keep track of whether the contact has a primary, secondary or tertiary role to the related account. Maintaining such a contact role hierarchy helps this customer when determining which contacts to reach out to for account specific communications. While maintaining this custom picklist, the customer noticed a common pattern and subsequently have asked for our help to automate and save them time. Here&#8217;s the pattern they would like us to enforce:<\/p>\r\n\r\n<p><em>When a non-primary contact is created Salesforce should set the same contacts \u201cReports To\u201d field with the primary contact of the same account in order to maintain a hierarchy within the contacts related to that account.<\/em> <em>Essentially, we have one primary contact, at a time, per account for whom all other contacts should report.<\/em><\/p>\r\n\r\n<p>After discussing this need a bit further, we have established some important clarifications and assumptions:<\/p>\r\n<p class=\"wp-block-paragraph\">\u00a0<\/p>\r\n\r\n<ul class=\"wp-block-list\">\r\n<li>We will use the existing custom Level__c picklist with values \u2018Primary, Secondary, Tertiary\u2019.<\/li>\r\n<li>We will use the existing standard lookup on contact, \u201cReports To,\u201d which is a self-referential lookup to contact.<\/li>\r\n<li>An account can be related to many contacts but only one contact will be the primary contact for that account.<\/li>\r\n<li>There is already automation in their Salesforce Org to ensure only one contact may be set \u2018primary\u2019 at a time.<\/li>\r\n<li>When a contact record is created with either the &#8216;secondary&#8217; or &#8216;tertiary&#8217; Level__c value and no primary contact record exists associated to the related account, the contact being created will be updated to the primary contact for the account.<\/li>\r\n<li>All contacts with either the &#8216;secondary&#8217; or &#8216;tertiary&#8217; Level__c value should have the \u201cReports To\u201d field updated with the Contact Id of the primary contact of the related account.<\/li>\r\n<\/ul>\r\n\r\n<p>&nbsp;<\/p>\r\n\r\n<p class=\"wp-block-paragraph\">\u00a0<\/p>\r\n\r\n<h3 class=\"wp-block-heading\" id=\"anchor-3\">Delivering a Flow Solution<\/h3>\r\n\r\n<p>Before we can get started, we need to agree the triggering event for this automation request, that is, when to intervene in the database <a href=\"https:\/\/developer.salesforce.com\/docs\/atlas.en-us.apexcode.meta\/apexcode\/apex_triggers_order_of_execution.htm\" target=\"_blank\" rel=\"noreferrer noopener\">order of execution<\/a>. As you may know, there is a growing list of Flow Types from screen flows, scheduled triggered flows, auto-launched flows, to record triggered flows and platform event triggered flows. Because we want our rule enforced on the contact at the time of record creation, we can use a record triggered flow. This Flow Type enables us to execute our logic behind the scenes before the new contact record is inserted into the database.<\/p>\r\n\r\n<p>Below pictured is the completed record triggered Flow. Don&#8217;t worry, we will step through it element by element.<\/p>\r\n<p class=\"wp-block-paragraph\">\u00a0<\/p>\r\n\r\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" class=\"wp-image-3334\" src=\"https:\/\/bluewavecx.com\/wp-content\/uploads\/2022\/04\/2022-04-27_11h11_04-1-1024x533.png\" alt=\"\" \/>\r\n<figcaption>Take a minute to examine the high-level design with it&#8217;s four distinct nodes.<\/figcaption>\r\n<\/figure>\r\n\r\n<p>&nbsp;<\/p>\r\n\r\n<p class=\"wp-block-paragraph\">\u00a0<\/p>\r\n\r\n<h4 class=\"wp-block-heading\" id=\"anchor-4\">Getting Started<\/h4>\r\n\r\n<p>After choosing a Flow Type, our next critical decision is determining how to optimise the Flow, in this case either for &#8216;Fast Field Updates&#8217; or &#8216;Actions and Related Records.&#8217; These optimisation choices correspond to before or after save events respectively in the order of execution. By choosing &#8216;Fast Field Updates,&#8217; we ensure our logic is evaluated before the record is saved in the database. The reason why a &#8216;Fast Field Update&#8217; or the equivalent before insert\/update trigger is the best approach here is because the logic is executed on the same record that fires the automation as opposed to any related records.<\/p>\r\n\r\n<p>Let&#8217;s configure the Flow start screen using the following values, like so:<\/p>\r\n<p class=\"wp-block-paragraph\">\u00a0<\/p>\r\n\r\n<figure class=\"wp-block-table\">\r\n<table>\r\n<tbody>\r\n<tr>\r\n<td><strong>Attribute<\/strong><\/td>\r\n<td><strong>Set As<\/strong><\/td>\r\n<\/tr>\r\n<tr>\r\n<td>Object<\/td>\r\n<td>Contact<\/td>\r\n<\/tr>\r\n<tr>\r\n<td>Configure Trigger<\/td>\r\n<td>Trigger the flow when a record is created<\/td>\r\n<\/tr>\r\n<tr>\r\n<td>Entry Criteria<\/td>\r\n<td>Level__c field on Contact has the value \u201cSecondary\u201d or \u201cTertiary\u201d<\/td>\r\n<\/tr>\r\n<tr>\r\n<td>Optimise the flow for<\/td>\r\n<td>Fast Field Updates<\/td>\r\n<\/tr>\r\n<\/tbody>\r\n<\/table>\r\n<\/figure>\r\n<p>\u00a0<\/p>\r\n\r\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" class=\"wp-image-3336\" src=\"https:\/\/bluewavecx.com\/wp-content\/uploads\/2022\/04\/2022-04-27_11h11_22-1-1024x491.png\" alt=\"\" \/><\/figure>\r\n<p>\u00a0<\/p>\r\n\r\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" class=\"wp-image-3501\" src=\"https:\/\/bluewavecx.com\/wp-content\/uploads\/2022\/04\/2022-04-29_13h11_27-1024x338.png\" alt=\"\" \/><\/figure>\r\n<p>\u00a0<\/p>\r\n\r\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" class=\"wp-image-3338\" src=\"https:\/\/bluewavecx.com\/wp-content\/uploads\/2022\/04\/2022-04-27_11h11_37-1-1024x218.png\" alt=\"\" \/><\/figure>\r\n\r\n<p>&nbsp;<\/p>\r\n\r\n<p class=\"wp-block-paragraph\">\u00a0<\/p>\r\n\r\n<h4 class=\"wp-block-heading\" id=\"anchor-5\">Node 1\/4 The Get Records Element<\/h4>\r\n\r\n<p>The <a href=\"https:\/\/help.salesforce.com\/s\/articleView?id=sf.flow_ref_elements_data_get.htm&amp;type=5\" target=\"_blank\" rel=\"noreferrer noopener\">Get Records element<\/a> is used to \u201c<em>Find Salesforce records that meet filter conditions, and store values from the records in variables<\/em>.\u201d We want to use this element to query the database in search of a Contact record related to the same Account with the Level__c value \u201cPrimary.&#8221; This related Contact record will then be used to set the \u201cReports To\u201d field on the original Contact record that started this flow. The variable \u2018$Record\u2019 in the screenshot below refers to the global variable already defined as the record that triggered this Flow and is available to use without any setup\/configuration of the variable.<\/p>\r\n<p class=\"wp-block-paragraph\">\u00a0<\/p>\r\n\r\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" class=\"wp-image-3340\" src=\"https:\/\/bluewavecx.com\/wp-content\/uploads\/2022\/04\/2022-04-27_11h11_59-1-1024x762.png\" alt=\"\" \/><\/figure>\r\n\r\n<p>&nbsp;<\/p>\r\n\r\n<p class=\"wp-block-paragraph\">&nbsp;<\/p>\r\n\r\n<p>We will only store one resulting Contact record as there can only be one \u201cPrimary\u201d Contact for each Account.<\/p>\r\n<p class=\"wp-block-paragraph\">\u00a0<\/p>\r\n\r\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" class=\"wp-image-3342\" src=\"https:\/\/bluewavecx.com\/wp-content\/uploads\/2022\/04\/2022-04-27_11h12_13-1-1024x474.png\" alt=\"\" \/><\/figure>\r\n\r\n<p>&nbsp;<\/p>\r\n\r\n<p class=\"wp-block-paragraph\">\u00a0<\/p>\r\n\r\n<h4 class=\"wp-block-heading\" id=\"anchor-6\">Node 2\/4 The Decision Element<\/h4>\r\n\r\n<p>Next, the <a href=\"https:\/\/help.salesforce.com\/s\/articleView?id=sf.flow_ref_elements_decision.htm&amp;type=5\" target=\"_blank\" rel=\"noreferrer noopener\">Decision element<\/a> is used to \u201c<em>Evaluate a set of conditions, and route users through the flow based on the outcomes of those conditions.<\/em>.\u201d Our decision will answer a simple question, &#8220;did we find a primary contact associated to the account?,&#8221; with two possible outcomes. If our Get Records element \u201cGet_Primary_Contact\u201d returned a Contact record then the outcome will be yes, otherwise the outcome will be no.<\/p>\r\n<p class=\"wp-block-paragraph\">\u00a0<\/p>\r\n\r\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" class=\"wp-image-3344\" src=\"https:\/\/bluewavecx.com\/wp-content\/uploads\/2022\/04\/2022-04-27_11h12_29-1-1024x414.png\" alt=\"\" \/><\/figure>\r\n\r\n<p>The \u201cNo\u201d outcome is the default decision without any conditions.<\/p>\r\n<p class=\"wp-block-paragraph\">\u00a0<\/p>\r\n\r\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" class=\"wp-image-3346\" src=\"https:\/\/bluewavecx.com\/wp-content\/uploads\/2022\/04\/2022-04-27_11h12_43-1-1024x481.png\" alt=\"\" \/><\/figure>\r\n\r\n<p>&nbsp;<\/p>\r\n\r\n<p class=\"wp-block-paragraph\">\u00a0<\/p>\r\n\r\n<h4 class=\"wp-block-heading\" id=\"anchor-7\">Node 3\/4 The &#8216;Reports To&#8217; Assignment Element<\/h4>\r\n\r\n<p>The <a href=\"https:\/\/help.salesforce.com\/s\/articleView?id=sf.flow_ref_elements_assignment.htm&amp;type=5\" target=\"_blank\" rel=\"noreferrer noopener\">Assignment element<\/a> is used to \u201c<em>Set values in variables, collection variables, record variables, record collection variables, and global variables<\/em>.\u201d When the outcome of our Decision element is \u201cYes\u201d then we want to set the \u201cReports To\u201d (Contact Lookup) field value on the Contact record that has been created to the Contact Id returned from the \u201cGet_Primary_Contact\u201d Get Records element.<\/p>\r\n<p class=\"wp-block-paragraph\">\u00a0<\/p>\r\n\r\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" class=\"wp-image-3348\" src=\"https:\/\/bluewavecx.com\/wp-content\/uploads\/2022\/04\/2022-04-27_11h12_59-1-1024x435.png\" alt=\"\" \/><\/figure>\r\n\r\n<p>&nbsp;<\/p>\r\n\r\n<p class=\"wp-block-paragraph\">\u00a0<\/p>\r\n\r\n<h4 class=\"wp-block-heading\" id=\"anchor-8\">Node 4\/4: The &#8216;Level&#8217; Assignment Element<\/h4>\r\n\r\n<p>Finally, we want to use a second Assignment element to handle when the outcome of the Decision element is \u201cNo.&#8221; Effectively, if no primary contact record is returned from our Get Records element then we will set the Level__c field on the Contact record that has been created to \u2018Primary\u2019.<\/p>\r\n<p class=\"wp-block-paragraph\">\u00a0<\/p>\r\n\r\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" class=\"wp-image-3349\" src=\"https:\/\/bluewavecx.com\/wp-content\/uploads\/2022\/04\/2022-04-27_11h13_36-1-1024x432.png\" alt=\"\" \/><\/figure>\r\n\r\n<p>&nbsp;<\/p>\r\n\r\n<p class=\"wp-block-paragraph\">\u00a0<\/p>\r\n\r\n<h3 class=\"wp-block-heading\" id=\"anchor-10\">Delivering an Apex Solution<\/h3>\r\n\r\n<p>&nbsp;<\/p>\r\n\r\n<p class=\"wp-block-paragraph\">\u00a0<\/p>\r\n\r\n<h4 class=\"wp-block-heading\" id=\"anchor-11\">The Trigger<\/h4>\r\n\r\n<p>First, we need to create a Apex Trigger on the Contact object, if it doesn&#8217;t have one, and equivalent starting point to specifying the Flows Type and Optimization strategy. Object oriented programming best practice promotes a single trigger per object avoiding any application logic directly in the trigger itself by using a handler class instead. For this example, we will establish a context condition to execute a new method however in a real-world scenario there might be further steps required to adhere to those best practices.<\/p>\r\n<p class=\"wp-block-paragraph\">\u00a0<\/p>\r\n\r\n<pre class=\"wp-block-code\"><code>trigger ContactTrigger on Contact (before insert) {\r\n    if(trigger.isbefore &amp;&amp; trigger.isInsert)\r\n\t{\r\n        ContactHelper.setReportsToAsPrimaryContact(trigger.new);\r\n\t}\r\n}<\/code><\/pre>\r\n\r\n<p>&nbsp;<\/p>\r\n\r\n<p class=\"wp-block-paragraph\">\u00a0<\/p>\r\n\r\n<h4 class=\"wp-block-heading\" id=\"anchor-12\">The Class<\/h4>\r\n\r\n<p>When a Contact record is inserted in the database, our new Apex method \u201csetReportsToAsPrimaryContact\u201d will be executed, passing a list of contact records in the context of trigger.new for our method to evaluate.<\/p>\r\n\r\n<p>Essentially, the same functionality as we developed in the Flow will now run in this Apex class; For every Contact record that is inserted, the following logic finds the \u2018Primary\u2019 Contact record for the related Account. Then this &#8216;Primary&#8217; Contact is stored in a map and retrieved from the map using the accountId as a key to set the relevant Contact record value.<\/p>\r\n\r\n<p>There is additional logic required in the Apex Class to handle bulk scenarios where multiple &#8216;non-primary&#8217; Contacts, related to the same Account, being inserted and a \u2018Primary\u2019 Contact record does not exist. When this occurs, one of the Contact records must be chosen to be set as the \u2018Primary\u2019 Contact record.<\/p>\r\n\r\n<p>While the resulting Apex method is simple enough, it requires an Apex developer to understand collections such as sets, lists and maps to be successful. Furthermore, they would surely follow coding standards like avoiding the use of DML or SOQL inside of For Loops.<\/p>\r\n<p class=\"wp-block-paragraph\">\u00a0<\/p>\r\n\r\n<pre class=\"wp-block-code\"><code>public class ContactHelper {\r\n\tpublic static void setReportsToAsPrimaryContact(List&lt;Contact&gt; newContacts)\r\n\t\/\/create set of account ids related to contact\r\n        Set&lt;Id&gt; accountIds = new Set&lt;Id&gt;();\r\n        for(Contact contact : newContacts)\r\n        {\r\n            if(!accountIds.contains(contact.accountId))\r\n            {\r\n            \taccountIds.add(contact.accountId);\r\n            }\r\n        }\r\n        \/\/get primary contacts for each account\r\n        List&lt;Contact&gt; primaryContactList = [SELECT Id, accountId FROM Contact WHERE AccountId IN:accountIds AND Level__c = 'Primary'];\r\n       \tMap&lt;Id, Contact&gt; primaryContactByAccountId = new Map&lt;Id, Contact&gt;();\r\n        for(Contact primaryContact : primaryContactList)\r\n        {\r\n            primaryContactByAccountId.put(primaryContact.accountId, primaryContact);\r\n        }\r\n        \/\/get primary contacts for each account\r\n        Map&lt;Id, List&lt;Contact&gt;&gt; nonPrimaryContactByAccountId = new Map&lt;Id, List&lt;Contact&gt;&gt;();\r\n        for(Contact nonPrimaryContact : newContacts)\r\n        {\r\n            if(!nonPrimaryContactByAccountId.containsKey(nonPrimaryContact.accountId))\r\n            {\r\n                nonPrimaryContactByAccountId.put(nonPrimaryContact.accountId, new List&lt;Contact&gt;{nonPrimaryContact});\r\n            }\r\n            else\r\n            {\r\nnonPrimaryContactByAccountId.get(nonPrimaryContact.accountId).add(nonPrimaryContact);\r\n            }\r\n        }\r\n        for(Contact updateContact : newContacts)\r\n        {\r\n            if(updateContact.Level__c != 'Primary')\r\n            {\r\n                Contact primaryContact = primaryContactByAccountId.get(updateContact.accountId);\r\n                if(primaryContact != null)\r\n                {\r\n                    \/\/set the reports to id for the new contacts created to the primary contact if one exists\r\n                \tupdateContact.ReportsToId = primaryContact.Id;\r\n                }\r\n                else\r\n                {\r\n                    \/\/if no primary contacts exists for the account then set the current contact as the primary\r\n                    \/\/if there are multiple contacts being inserted related to the same account then get the first contact from the insert list\r\n                    \/\/and set that contact as the primary one\r\n                    List&lt;Contact&gt; nonPrimaryContacts = nonPrimaryContactByAccountId.get(updateContact.accountId);\r\n                    if(nonPrimaryContacts.size() &gt; 1)\r\n                    {\r\n                        nonPrimaryContacts[0].Level__c = 'Primary';\r\n                    }\r\n                    else\r\n                    {\r\n                   \t\tupdateContact.Level__c = 'Primary';\r\n                    }\r\n                }\r\n            }\r\n        }\r\n        \/\/no update dml required as this will be called from a before insert trigger\r\n\t}\r\n}<\/code><\/pre>\r\n\r\n<p>&nbsp;<\/p>\r\n\r\n<p class=\"wp-block-paragraph\">\u00a0<\/p>\r\n\r\n<h4 class=\"wp-block-heading\" id=\"anchor-13\">The Unit Tests<\/h4>\r\n\r\n<p>To promote Apex to production, any snippet of Apex must have quality unit tests covering a minimum of 75% of the logic therein. This is a hard requirement by Salesforce. And it often takes a similar amount of time to author unit tests in a Test Class as it takes a programmatic developer to write the logic in an Apex Class. In fact, many developers prefer to write the unit tests first as a means of confirming the testable conditions and outcomes of the logic. Unit Tests will cover positive, negative and bulk processing scenarios for the associated logic. And these unit tests must be maintained along with the application logic when business processes are added, changed, or deprecated in the future.<\/p>\r\n\r\n<p>&nbsp;<\/p>\r\n\r\n<p class=\"wp-block-paragraph\">\u00a0<\/p>\r\n\r\n<h3 class=\"wp-block-heading\" id=\"anchor-14\">Conclusion<\/h3>\r\n\r\n<p>Applying the problem-solving principle, &#8220;<em>The simplest solution is always the best<\/em>,&#8221; going forward if we can use Flow over Apex, we should. And due to substantial increases in the abilities of Flow over the last few release cycles, there is an ever growing list of use cases where Apex is no longer required. Where we, as Salesforce practitioners, need to use caution is in our own bias. Declarative (that is point-and-click) developers need to understand the limitations of Flow just as thoroughly as Programmatic Developers to avoid forcing the wrong solution forward simply because it was the toolset they were most familiar with. Without a doubt, there will always be a need for Apex on the Salesforce Platform but with the expansion of the Flow capability set, it means Programmatic Developers can refocus on more complex challenges. Below is a recap of pros and cons from the above business scenario.<\/p>\r\n\r\n<p>&nbsp;<\/p>\r\n\r\n<p class=\"wp-block-paragraph\">\u00a0<\/p>\r\n\r\n<div class=\"wp-block-group\"><div class=\"wp-block-group__inner-container is-layout-flow wp-block-group-is-layout-flow\">\r\n<h2 class=\"has-text-color wp-block-heading\" style=\"color: #ba0c49; font-size: 38px;\">\u00a0<\/h2>\r\n\r\n\r\n\r\n<div class=\"wp-block-columns is-layout-flex wp-container-core-columns-is-layout-8f761849 wp-block-columns-is-layout-flex\">\r\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\">\r\n<p><span style=\"text-decoration: underline;\"><strong>PROS of a Flow Solution<\/strong><\/span><\/p>\r\n\r\n\r\n\r\n<ul class=\"wp-block-list\">\r\n<li>No programming means less time to delivery and reduced long-term maintenance effort<\/li>\r\n<li>A Flow solution doesn&#8217;t require programming skills to build, test, implement or maintain.<\/li>\r\n<li>Record Triggered Fast Field Updates actually use less CPU than Before Insert Update Apex.<\/li>\r\n<\/ul>\r\n\r\n<p><strong><span style=\"text-decoration: underline;\">CONS of a Flow Solution<\/span><\/strong><\/p>\r\n\r\n\r\n\r\n<ul class=\"wp-block-list\">\r\n<li>A Flow solution can either process records synchronously or asynchronously but not both. In this way, we are somewhat limited in our ability to address LDVs.<\/li>\r\n<li>A Flow solution is fundamentally less scalable than Apex, this is the trade-off for simplicity, and so you may bump into limitations as business processes become more complex.<\/li>\r\n<li>While debugging Flows is possible, it is not as robust as Apex where system.debug() can be added after any line in the code to facilitate troubleshooting.<\/li>\r\n<\/ul>\r\n<p><\/p>\r\n<\/div>\r\n\r\n\r\n\r\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\">\r\n<p><strong><span style=\"text-decoration: underline;\">PROS of an Apex Solution<\/span><\/strong><\/p>\r\n\r\n\r\n\r\n<ul class=\"wp-block-list\">\r\n<li>An Apex solution is scalable to handle all forms of bulk processing (including the option to process records asynchronously).<\/li>\r\n<li>Apex has very robust methods for troubleshooting application logic and unit tests.<\/li>\r\n<li>Apex offers more possibilities for further enhancements.<\/li>\r\n<\/ul>\r\n\r\n<p><strong><span style=\"text-decoration: underline;\">CONS of an Apex Solution<\/span><\/strong><\/p>\r\n\r\n\r\n\r\n<ul class=\"wp-block-list\">\r\n<li>An Apex solution generally takes more time to deliver and maintain than the equivalent Flow solution.<\/li>\r\n<li>An Apex solution requires programming skills to build, test, implement and maintain.<\/li>\r\n<li>An Apex solution requires additional logic and unit tests to be written to cover bulk scenarios.<\/li>\r\n<\/ul>\r\n<p><\/p>\r\n<\/div>\r\n<p><\/p>\r\n<\/div>\r\n<p><\/p>\r\n<\/div><\/div>\r\n<p>\u00a0<\/p>\r\n\r\n<p class=\"has-medium-font-size wp-block-paragraph\">If you enjoyed this post, may we suggest:<\/p>\r\n<p>\u00a0<\/p>\r\n\r\n<ul class=\"wp-block-list\">\r\n<li><a href=\"https:\/\/bluewavecx.com\/ie\/blog\/flow-saves-the-guest-user\/\">How Salesforce Flow Saves The Guest User Experience<\/a><\/li>\r\n<li><a href=\"https:\/\/bluewavecx.com\/ie\/blog\/demystifying-throughput-for-lightning-flow\/\">Demystifying throughput for Lightning Flow<\/a><\/li>\r\n<\/ul>\r\n\r\n<p>Don\u2019t hesitate to enquire how <strong>Bluewave Technology<\/strong> can assist with any challenges you are facing within your Salesforce environment. We are Salesforce experts with two decades of success supporting Pardot, Sales Cloud, Service Cloud, Analytics Cloud, Experience Cloud, Marketing Cloud, Project Management, Integration, and Release Management.<\/p>\r\n<p class=\"wp-block-paragraph\">\u00a0<\/p>\r\n\r\n<div class=\"wp-block-contact-form-7-contact-form-selector\">\r\n<div id=\"wpcf7-f1810-p3283-o7\" class=\"wpcf7\" dir=\"ltr\" lang=\"en-GB\" role=\"form\">\r\n<div class=\"screen-reader-response\">\r\n<p role=\"status\">\u00a0<\/p>\r\n<\/div>\r\n<div>\u00a0<\/div>\r\n<p><label> First Name (required)<\/label><\/p>\r\n<p><label> Last Name (required)<\/label><\/p>\r\n<p><label> Your Email (required)<\/label><\/p>\r\n<p><label> Company Name (required)<\/label><\/p>\r\n<p><label> Your Message<\/label><\/p>\r\n<p>&nbsp;<\/p>\r\n<div class=\"wpcf7-response-output\" aria-hidden=\"true\">\u00a0<\/div>\r\n<\/div>\r\n<\/div>\r\n\r\n<p>&nbsp;<\/p>\r\n\r\n<p>&nbsp;<\/p>\r\n<p>[\/vc_column_text][\/vc_column][\/vc_row]<\/p><\/div>","protected":false},"excerpt":{"rendered":"<p>A Retrospective on using Apex or Flow to solve for the Same Business Scenario in Salesforce.<\/p>\n","protected":false},"author":1,"featured_media":4075,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"inline_featured_image":false,"footnotes":""},"categories":[2],"tags":[],"class_list":["post-3283","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-articles"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v28.7 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Match Fight: Apex v Flow. Who Wins in 2022? | Bluewave IE<\/title>\n<meta name=\"description\" content=\"Let&#039;s examine Flow against Apex in Salesforce for the same business scenario in order to draw some conclusions about the pros and cons of each.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/bluewavecx.com\/ie\/blog\/apex-v-flow-in-2022\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Match Fight: Apex v Flow. Who Wins in 2022? | Bluewave IE\" \/>\n<meta property=\"og:description\" content=\"Let&#039;s examine Flow against Apex in Salesforce for the same business scenario in order to draw some conclusions about the pros and cons of each.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/bluewavecx.com\/ie\/blog\/apex-v-flow-in-2022\/\" \/>\n<meta property=\"og:site_name\" content=\"Bluewave IE\" \/>\n<meta property=\"article:published_time\" content=\"2022-05-04T09:50:40+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-01-17T13:17:44+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/bluewavecx.com\/ie\/wp-content\/uploads\/sites\/2\/2022\/05\/18.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1800\" \/>\n\t<meta property=\"og:image:height\" content=\"1013\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"12 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/bluewavecx.com\\\/ie\\\/blog\\\/apex-v-flow-in-2022\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/bluewavecx.com\\\/ie\\\/blog\\\/apex-v-flow-in-2022\\\/\"},\"author\":{\"name\":\"admin\",\"@id\":\"https:\\\/\\\/bluewavecx.com\\\/ie\\\/#\\\/schema\\\/person\\\/3016812de924321d92720c9194e60684\"},\"headline\":\"Match Fight: Apex v Flow. Who Wins in 2022?\",\"datePublished\":\"2022-05-04T09:50:40+00:00\",\"dateModified\":\"2023-01-17T13:17:44+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/bluewavecx.com\\\/ie\\\/blog\\\/apex-v-flow-in-2022\\\/\"},\"wordCount\":2040,\"commentCount\":0,\"image\":{\"@id\":\"https:\\\/\\\/bluewavecx.com\\\/ie\\\/blog\\\/apex-v-flow-in-2022\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/bluewavecx.com\\\/ie\\\/wp-content\\\/uploads\\\/sites\\\/2\\\/2022\\\/05\\\/18.png\",\"articleSection\":[\"Articles\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/bluewavecx.com\\\/ie\\\/blog\\\/apex-v-flow-in-2022\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/bluewavecx.com\\\/ie\\\/blog\\\/apex-v-flow-in-2022\\\/\",\"url\":\"https:\\\/\\\/bluewavecx.com\\\/ie\\\/blog\\\/apex-v-flow-in-2022\\\/\",\"name\":\"Match Fight: Apex v Flow. Who Wins in 2022? | Bluewave IE\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/bluewavecx.com\\\/ie\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/bluewavecx.com\\\/ie\\\/blog\\\/apex-v-flow-in-2022\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/bluewavecx.com\\\/ie\\\/blog\\\/apex-v-flow-in-2022\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/bluewavecx.com\\\/ie\\\/wp-content\\\/uploads\\\/sites\\\/2\\\/2022\\\/05\\\/18.png\",\"datePublished\":\"2022-05-04T09:50:40+00:00\",\"dateModified\":\"2023-01-17T13:17:44+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/bluewavecx.com\\\/ie\\\/#\\\/schema\\\/person\\\/3016812de924321d92720c9194e60684\"},\"description\":\"Let's examine Flow against Apex in Salesforce for the same business scenario in order to draw some conclusions about the pros and cons of each.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/bluewavecx.com\\\/ie\\\/blog\\\/apex-v-flow-in-2022\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/bluewavecx.com\\\/ie\\\/blog\\\/apex-v-flow-in-2022\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/bluewavecx.com\\\/ie\\\/blog\\\/apex-v-flow-in-2022\\\/#primaryimage\",\"url\":\"https:\\\/\\\/bluewavecx.com\\\/ie\\\/wp-content\\\/uploads\\\/sites\\\/2\\\/2022\\\/05\\\/18.png\",\"contentUrl\":\"https:\\\/\\\/bluewavecx.com\\\/ie\\\/wp-content\\\/uploads\\\/sites\\\/2\\\/2022\\\/05\\\/18.png\",\"width\":1800,\"height\":1013},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/bluewavecx.com\\\/ie\\\/blog\\\/apex-v-flow-in-2022\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/bluewavecx.com\\\/ie\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Match Fight: Apex v Flow. Who Wins in 2022?\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/bluewavecx.com\\\/ie\\\/#website\",\"url\":\"https:\\\/\\\/bluewavecx.com\\\/ie\\\/\",\"name\":\"Bluewave IE\",\"description\":\"Just another bluewavegroup site\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/bluewavecx.com\\\/ie\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/bluewavecx.com\\\/ie\\\/#\\\/schema\\\/person\\\/3016812de924321d92720c9194e60684\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/7186641f2ccd92cf6444aea05ab53d302332efd95634f833be3085ce466e00b6?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/7186641f2ccd92cf6444aea05ab53d302332efd95634f833be3085ce466e00b6?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/7186641f2ccd92cf6444aea05ab53d302332efd95634f833be3085ce466e00b6?s=96&d=mm&r=g\",\"caption\":\"admin\"},\"sameAs\":[\"http:\\\/\\\/bluewavegroup.flywheelstaging.com\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Match Fight: Apex v Flow. Who Wins in 2022? | Bluewave IE","description":"Let's examine Flow against Apex in Salesforce for the same business scenario in order to draw some conclusions about the pros and cons of each.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/bluewavecx.com\/ie\/blog\/apex-v-flow-in-2022\/","og_locale":"en_US","og_type":"article","og_title":"Match Fight: Apex v Flow. Who Wins in 2022? | Bluewave IE","og_description":"Let's examine Flow against Apex in Salesforce for the same business scenario in order to draw some conclusions about the pros and cons of each.","og_url":"https:\/\/bluewavecx.com\/ie\/blog\/apex-v-flow-in-2022\/","og_site_name":"Bluewave IE","article_published_time":"2022-05-04T09:50:40+00:00","article_modified_time":"2023-01-17T13:17:44+00:00","og_image":[{"width":1800,"height":1013,"url":"https:\/\/bluewavecx.com\/ie\/wp-content\/uploads\/sites\/2\/2022\/05\/18.png","type":"image\/png"}],"author":"admin","twitter_card":"summary_large_image","twitter_misc":{"Written by":"admin","Est. reading time":"12 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/bluewavecx.com\/ie\/blog\/apex-v-flow-in-2022\/#article","isPartOf":{"@id":"https:\/\/bluewavecx.com\/ie\/blog\/apex-v-flow-in-2022\/"},"author":{"name":"admin","@id":"https:\/\/bluewavecx.com\/ie\/#\/schema\/person\/3016812de924321d92720c9194e60684"},"headline":"Match Fight: Apex v Flow. Who Wins in 2022?","datePublished":"2022-05-04T09:50:40+00:00","dateModified":"2023-01-17T13:17:44+00:00","mainEntityOfPage":{"@id":"https:\/\/bluewavecx.com\/ie\/blog\/apex-v-flow-in-2022\/"},"wordCount":2040,"commentCount":0,"image":{"@id":"https:\/\/bluewavecx.com\/ie\/blog\/apex-v-flow-in-2022\/#primaryimage"},"thumbnailUrl":"https:\/\/bluewavecx.com\/ie\/wp-content\/uploads\/sites\/2\/2022\/05\/18.png","articleSection":["Articles"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/bluewavecx.com\/ie\/blog\/apex-v-flow-in-2022\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/bluewavecx.com\/ie\/blog\/apex-v-flow-in-2022\/","url":"https:\/\/bluewavecx.com\/ie\/blog\/apex-v-flow-in-2022\/","name":"Match Fight: Apex v Flow. Who Wins in 2022? | Bluewave IE","isPartOf":{"@id":"https:\/\/bluewavecx.com\/ie\/#website"},"primaryImageOfPage":{"@id":"https:\/\/bluewavecx.com\/ie\/blog\/apex-v-flow-in-2022\/#primaryimage"},"image":{"@id":"https:\/\/bluewavecx.com\/ie\/blog\/apex-v-flow-in-2022\/#primaryimage"},"thumbnailUrl":"https:\/\/bluewavecx.com\/ie\/wp-content\/uploads\/sites\/2\/2022\/05\/18.png","datePublished":"2022-05-04T09:50:40+00:00","dateModified":"2023-01-17T13:17:44+00:00","author":{"@id":"https:\/\/bluewavecx.com\/ie\/#\/schema\/person\/3016812de924321d92720c9194e60684"},"description":"Let's examine Flow against Apex in Salesforce for the same business scenario in order to draw some conclusions about the pros and cons of each.","breadcrumb":{"@id":"https:\/\/bluewavecx.com\/ie\/blog\/apex-v-flow-in-2022\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/bluewavecx.com\/ie\/blog\/apex-v-flow-in-2022\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/bluewavecx.com\/ie\/blog\/apex-v-flow-in-2022\/#primaryimage","url":"https:\/\/bluewavecx.com\/ie\/wp-content\/uploads\/sites\/2\/2022\/05\/18.png","contentUrl":"https:\/\/bluewavecx.com\/ie\/wp-content\/uploads\/sites\/2\/2022\/05\/18.png","width":1800,"height":1013},{"@type":"BreadcrumbList","@id":"https:\/\/bluewavecx.com\/ie\/blog\/apex-v-flow-in-2022\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/bluewavecx.com\/ie\/"},{"@type":"ListItem","position":2,"name":"Match Fight: Apex v Flow. Who Wins in 2022?"}]},{"@type":"WebSite","@id":"https:\/\/bluewavecx.com\/ie\/#website","url":"https:\/\/bluewavecx.com\/ie\/","name":"Bluewave IE","description":"Just another bluewavegroup site","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/bluewavecx.com\/ie\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/bluewavecx.com\/ie\/#\/schema\/person\/3016812de924321d92720c9194e60684","name":"admin","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/7186641f2ccd92cf6444aea05ab53d302332efd95634f833be3085ce466e00b6?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/7186641f2ccd92cf6444aea05ab53d302332efd95634f833be3085ce466e00b6?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/7186641f2ccd92cf6444aea05ab53d302332efd95634f833be3085ce466e00b6?s=96&d=mm&r=g","caption":"admin"},"sameAs":["http:\/\/bluewavegroup.flywheelstaging.com"]}]}},"_links":{"self":[{"href":"https:\/\/bluewavecx.com\/ie\/wp-json\/wp\/v2\/posts\/3283","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/bluewavecx.com\/ie\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/bluewavecx.com\/ie\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/bluewavecx.com\/ie\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/bluewavecx.com\/ie\/wp-json\/wp\/v2\/comments?post=3283"}],"version-history":[{"count":2,"href":"https:\/\/bluewavecx.com\/ie\/wp-json\/wp\/v2\/posts\/3283\/revisions"}],"predecessor-version":[{"id":4884,"href":"https:\/\/bluewavecx.com\/ie\/wp-json\/wp\/v2\/posts\/3283\/revisions\/4884"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/bluewavecx.com\/ie\/wp-json\/wp\/v2\/media\/4075"}],"wp:attachment":[{"href":"https:\/\/bluewavecx.com\/ie\/wp-json\/wp\/v2\/media?parent=3283"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/bluewavecx.com\/ie\/wp-json\/wp\/v2\/categories?post=3283"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/bluewavecx.com\/ie\/wp-json\/wp\/v2\/tags?post=3283"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}