{"id":5042,"date":"2016-02-08T06:18:35","date_gmt":"2016-02-08T06:18:35","guid":{"rendered":"http:\/\/www.jitendrazaa.com\/blog\/?p=5042"},"modified":"2016-06-27T00:03:20","modified_gmt":"2016-06-27T00:03:20","slug":"why-to-avoid-using-workflow-rule-and-process-builder-field-update-with-trigger","status":"publish","type":"post","link":"https:\/\/www.jitendrazaa.com\/blog\/salesforce\/why-to-avoid-using-workflow-rule-and-process-builder-field-update-with-trigger\/","title":{"rendered":"Why to avoid using Workflow rule and Process Builder field update with Trigger"},"content":{"rendered":"<p style=\"text-align: justify;\"><a href=\"https:\/\/www.jitendrazaa.com\/blog\/tag\/workflow\/\">Workflow rule<\/a> and <a href=\"https:\/\/www.jitendrazaa.com\/blog\/tag\/process-builder\/\">Process builder<\/a> are the tools because of which Salesforce Admins can perform so many tasks, which were only possible by writing <a href=\"https:\/\/www.jitendrazaa.com\/blog\/tag\/trigger\/\">Triggers<\/a>. Before release of Process builder, if we wanted to perform field update on child records or post chatter messages or auto execute Visual Flow,\u00a0Triggers were used by developers.<\/p>\n<p style=\"text-align: justify;\">As a best practice in Salesforce, it is always suggested that we should prefer &#8220;point and clicks&#8221; over code. Indirectly, prefer Workflow rule or Process builder over Triggers.<\/p>\n<figure id=\"attachment_5280\" aria-describedby=\"caption-attachment-5280\" style=\"width: 770px\" class=\"wp-caption alignleft\"><a href=\"https:\/\/i0.wp.com\/www.jitendrazaa.com\/blog\/wp-content\/uploads\/2016\/02\/Trigger-Workflow-and-Process-Builder.png?ssl=1\" rel=\"attachment wp-att-5280\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-5280\" src=\"https:\/\/i0.wp.com\/www.jitendrazaa.com\/blog\/wp-content\/uploads\/2016\/02\/Trigger-Workflow-and-Process-Builder.png?resize=770%2C400&#038;ssl=1\" alt=\"Trigger Workflow and Process Builder in Salesforce\" width=\"770\" height=\"400\" srcset=\"https:\/\/i0.wp.com\/www.jitendrazaa.com\/blog\/wp-content\/uploads\/2016\/02\/Trigger-Workflow-and-Process-Builder.png?w=770&amp;ssl=1 770w, https:\/\/i0.wp.com\/www.jitendrazaa.com\/blog\/wp-content\/uploads\/2016\/02\/Trigger-Workflow-and-Process-Builder.png?resize=300%2C156&amp;ssl=1 300w, https:\/\/i0.wp.com\/www.jitendrazaa.com\/blog\/wp-content\/uploads\/2016\/02\/Trigger-Workflow-and-Process-Builder.png?resize=768%2C399&amp;ssl=1 768w\" sizes=\"auto, (max-width: 770px) 100vw, 770px\" \/><\/a><figcaption id=\"caption-attachment-5280\" class=\"wp-caption-text\">Trigger, Workflow and Process Builder in Salesforce<\/figcaption><\/figure>\n<p>In this post, I will explain a scenario where above statement will not stand true.<!--more--><\/p>\n<h3 style=\"text-align: justify;\">Using Trigger<\/h3>\n<p style=\"text-align: justify;\">Lets consider that there is a trigger written on custom object &#8220;Vehicle__c&#8221;. For simplicity, below trigger just have\u00a0some debug statements.<\/p>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\r\ntrigger Vehicle_Trigger on Vehicle__c (before insert, before update, after insert, after update) {\r\n    \r\n    if(Trigger.isBefore){\r\n        \/\/some other code and SOQL statements\r\n        System.debug('******** - In Before Update Trigger');\r\n    }\r\n    if(Trigger.isAfter){\r\n        \/\/some other code and SOQL statements\r\n        System.debug('******** - In After Update Trigger');\r\n    }\r\n\r\n}\r\n<\/pre>\n<p style=\"text-align: justify;\">Whenever any record of custom object &#8220;Vehicle__c&#8221; is updated or created, above trigger will execute &#8220;<strong>two times<\/strong>&#8221; in before and after event. To know more about sequence of execution of trigger, you can <a href=\"https:\/\/developer.salesforce.com\/docs\/atlas.en-us.apexcode.meta\/apexcode\/apex_triggers_order_of_execution.htm\">refer this link<\/a>.<\/p>\n<p><strong>output :<\/strong><\/p>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\r\n******** - In Before Update Trigger\r\n******** - In After Update Trigger\r\n<\/pre>\n<h3>Trigger and Workflow field update<\/h3>\n<p style=\"text-align: justify;\">Let&#8217;s say after sometime, requirement came to calculate and update field on Vehicle object. Considering timeline to deliver this requirement, team decided to choose Workflow field update over modifying existing trigger. Consider that workflow rule is written to execute every time when record is either created or updated.<\/p>\n<p style=\"text-align: justify;\">Now, whenever any record of custom object &#8220;Vehicle__c&#8221; is updated or created, chances that trigger will execute will be &#8220;<strong>four times<\/strong>&#8221; because of sequence of execution.<\/p>\n<p style=\"text-align: justify;\">When record is created or updated trigger will execute twice (before and after event) and after that workflow field update will cause trigger to execute again (before and after event).<\/p>\n<p><strong>output :<\/strong><\/p>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\r\n******** - In Before Update Trigger\r\n******** - In After Update Trigger\r\n... WF rule operation if condition meets ...\r\n******** - In Before Update Trigger\r\n******** - In After Update Trigger\r\n<\/pre>\n<h3>Trigger, Workflow and Process builder field update<\/h3>\n<p style=\"text-align: justify;\">To make situation worst, if we write f<em>ield update<\/em> on same object &#8220;<em>Vehicle<\/em>&#8221; in Process builder also then trigger may\u00a0execute &#8220;<strong>six times<\/strong>&#8221; instead of only two times.<\/p>\n<p style=\"text-align: justify;\">In this case, whenever any record is created or updated on custom object &#8220;Vehicle__c&#8221; then trigger will execute twice after that workflow field update will cause its execution again. After workflow field update, process builder will update record again causing execution of trigger again.<\/p>\n<p style=\"text-align: justify;\"><strong>Difference between Workflow and Process builder field updat<\/strong>e<\/p>\n<p style=\"text-align: justify;\">If field update is done using Process builder, then record will go through complete Save cycle again.<\/p>\n<p style=\"text-align: justify;\">If field update is done using Workflow field update, then Custom validation rules, duplicate rules, and escalation rules will\u00a0not run again. <a href=\"https:\/\/developer.salesforce.com\/docs\/atlas.en-us.apexcode.meta\/apexcode\/apex_triggers_order_of_execution.htm\">Read here more<\/a>.<\/p>\n<p style=\"text-align: justify;\">We can avoid multiple execution of trigger by <a href=\"https:\/\/www.jitendrazaa.com\/blog\/salesforce\/salesforce-interview-questions-part-3\/\">using static variable<\/a>\u00a0(Question 26). However, if trigger is already written then instead of creating workflow or process builder field update, its wise decision to use existing trigger for field update. Multiple execution of trigger could cause hitting various governor limits like SOQL query or concurrent apex limit.<\/p>\n<p><strong>output :<\/strong><\/p>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\r\n******** - In Before Update Trigger\r\n******** - In After Update Trigger\r\n... WF rule operation if condition meets ...\r\n******** - In Before Update Trigger\r\n******** - In After Update Trigger\r\n... Process builder if condition meets ...\r\n******** - In Before Update Trigger\r\n******** - In After Update Trigger\r\n<\/pre>\n<h3 style=\"text-align: justify;\">Roll-Up Summary Field and its implications<\/h3>\n<p style=\"text-align: justify;\">If trigger is written on Master object and &#8220;<strong>Roll-Up summary field<\/strong>&#8221; is created on it. If child record creation , updation causes Roll-Up summary field to recalculate, then parent record undergoes through save operation causing its trigger to execute again.<\/p>\n<p style=\"text-align: justify;\">In short, having trigger, workflow and process builder field update on same object at same time (same condition) is not a good idea and it should be analysed carefully before deploying to production.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Consideration before using Trigger, Workflow and Process builder field update at same time in Salesforce<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"advanced_seo_description":"","jetpack_seo_html_title":"","jetpack_seo_noindex":false,"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"jz_research_post":"","_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[9],"tags":[307,360,280],"class_list":["post-5042","post","type-post","status-publish","format-standard","hentry","category-salesforce","tag-process-builder","tag-roll-up-summary-field","tag-workflow"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack-related-posts":[{"id":6160,"url":"https:\/\/www.jitendrazaa.com\/blog\/salesforce\/use-hierarchy-custom-settings-to-avoid-hard-coding-in-formula-field-custom-button-process-builder-or-workflow-rules\/","url_meta":{"origin":5042,"position":0},"title":"Use Hierarchy custom settings to avoid hard coding in formula field, custom button, process builder or workflow rules","author":"Jitendra","date":"June 30, 2017","format":false,"excerpt":"Example of using Hierarchy custom settings in formula field, custom button, process builder and workflow rules. Youtube video included.","rel":"","context":"In &quot;Salesforce&quot;","block_context":{"text":"Salesforce","link":"https:\/\/www.jitendrazaa.com\/blog\/category\/salesforce\/"},"img":{"alt_text":"Avoid Hard-coding Ids in Salesforce","src":"https:\/\/i0.wp.com\/www.jitendrazaa.com\/blog\/wp-content\/uploads\/2017\/06\/Avoid-Harcoding-Ids-in-Salesforce.jpg?fit=1188%2C621&ssl=1&resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.jitendrazaa.com\/blog\/wp-content\/uploads\/2017\/06\/Avoid-Harcoding-Ids-in-Salesforce.jpg?fit=1188%2C621&ssl=1&resize=350%2C200 1x, https:\/\/i0.wp.com\/www.jitendrazaa.com\/blog\/wp-content\/uploads\/2017\/06\/Avoid-Harcoding-Ids-in-Salesforce.jpg?fit=1188%2C621&ssl=1&resize=525%2C300 1.5x, https:\/\/i0.wp.com\/www.jitendrazaa.com\/blog\/wp-content\/uploads\/2017\/06\/Avoid-Harcoding-Ids-in-Salesforce.jpg?fit=1188%2C621&ssl=1&resize=700%2C400 2x, https:\/\/i0.wp.com\/www.jitendrazaa.com\/blog\/wp-content\/uploads\/2017\/06\/Avoid-Harcoding-Ids-in-Salesforce.jpg?fit=1188%2C621&ssl=1&resize=1050%2C600 3x"},"classes":[]},{"id":1233,"url":"https:\/\/www.jitendrazaa.com\/blog\/salesforce\/step-by-step-salesforce-tutorial-creating-workflow-rule-5-of-n\/","url_meta":{"origin":5042,"position":1},"title":"Step by Step Salesforce Tutorial \u2013 Creating Workflow rule \u2013 5 of 6","author":"Jitendra","date":"October 10, 2010","format":false,"excerpt":"Step by Step Salesforce Tutorial \u2013 Creating Workflow rule \u2013 5 of n","rel":"","context":"In &quot;Salesforce&quot;","block_context":{"text":"Salesforce","link":"https:\/\/www.jitendrazaa.com\/blog\/category\/salesforce\/"},"img":{"alt_text":"Salesforce creating Workflow rule step 1","src":"https:\/\/i0.wp.com\/jitendrazaa.com\/blog\/wp-content\/uploads\/2010\/10\/Salesforce-creating-Workflow-rule-step-1.jpg?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":4136,"url":"https:\/\/www.jitendrazaa.com\/blog\/salesforce\/salesforce-spring-15-some-highlighted-features\/","url_meta":{"origin":5042,"position":2},"title":"Salesforce Spring 15 &#8211; some highlighted features","author":"Jitendra","date":"December 28, 2014","format":false,"excerpt":"Download PDF version of release notes from here. 1. Import Account \/ Contact from 16 different sources (previously generic csv was only option to import). 2. Salesforce Analytics Query language (SAQL) We already know about SOQL and SOSL. This is new Query language for Analytics cloud to enable ad hoc\u2026","rel":"","context":"In &quot;Salesforce&quot;","block_context":{"text":"Salesforce","link":"https:\/\/www.jitendrazaa.com\/blog\/category\/salesforce\/"},"img":{"alt_text":"Case Macro - Spring 15","src":"https:\/\/i0.wp.com\/www.jitendrazaa.com\/blog\/wp-content\/uploads\/2014\/12\/Case-Macro-Spring-15.jpg?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.jitendrazaa.com\/blog\/wp-content\/uploads\/2014\/12\/Case-Macro-Spring-15.jpg?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/www.jitendrazaa.com\/blog\/wp-content\/uploads\/2014\/12\/Case-Macro-Spring-15.jpg?resize=525%2C300&ssl=1 1.5x, https:\/\/i0.wp.com\/www.jitendrazaa.com\/blog\/wp-content\/uploads\/2014\/12\/Case-Macro-Spring-15.jpg?resize=700%2C400&ssl=1 2x"},"classes":[]},{"id":4402,"url":"https:\/\/www.jitendrazaa.com\/blog\/salesforce\/using-selenium-to-test-workflow-field-update-action-salesforce-automated-testing-video-tutorial-part-2\/","url_meta":{"origin":5042,"position":3},"title":"Using Selenium to test workflow field update action &#8211; Salesforce automated testing &#8211; Video tutorial &#8211; Part 2","author":"Jitendra","date":"April 27, 2015","format":false,"excerpt":"We have already discussed\u00a0basics of selenium and how we can use this tool for automated testing.\u00a0Here we will see how we can take advantage of Selenium to test workflow field update. in this article we will create a simple workflow rule on Lead object and update \"Description\" field by adding\u2026","rel":"","context":"In &quot;Salesforce&quot;","block_context":{"text":"Salesforce","link":"https:\/\/www.jitendrazaa.com\/blog\/category\/salesforce\/"},"img":{"alt_text":"Salesforce Workflow rule - field update on Lead","src":"https:\/\/i0.wp.com\/www.jitendrazaa.com\/blog\/wp-content\/uploads\/2015\/04\/Salesforce-Workflow-rule-field-update-on-Lead.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.jitendrazaa.com\/blog\/wp-content\/uploads\/2015\/04\/Salesforce-Workflow-rule-field-update-on-Lead.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/www.jitendrazaa.com\/blog\/wp-content\/uploads\/2015\/04\/Salesforce-Workflow-rule-field-update-on-Lead.png?resize=525%2C300&ssl=1 1.5x, https:\/\/i0.wp.com\/www.jitendrazaa.com\/blog\/wp-content\/uploads\/2015\/04\/Salesforce-Workflow-rule-field-update-on-Lead.png?resize=700%2C400&ssl=1 2x"},"classes":[]},{"id":6794,"url":"https:\/\/www.jitendrazaa.com\/blog\/salesforce\/cannot-change-both-unitprice-and-totalprice-in-update-call\/","url_meta":{"origin":5042,"position":4},"title":"Cannot change both &#8216;UnitPrice&#8217; and &#8216;TotalPrice&#8217; in update call","author":"Jitendra","date":"February 24, 2019","format":false,"excerpt":"Trigger to change UnitPrice in Salesforce","rel":"","context":"In &quot;Salesforce&quot;","block_context":{"text":"Salesforce","link":"https:\/\/www.jitendrazaa.com\/blog\/category\/salesforce\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":4942,"url":"https:\/\/www.jitendrazaa.com\/blog\/salesforce\/salesforce-winter-16-top-features\/","url_meta":{"origin":5042,"position":5},"title":"Salesforce Winter 16 &#8211; Top features","author":"Jitendra","date":"October 28, 2015","format":false,"excerpt":"You can watch recording of my live stream channel as well to know more on Winter 16 features.\u00a0Powerpoint presentation used in livestream can be accessed from here. 1. Object Manager Objects are objects, even if they are standard or custom objects. Salesforce simplified navigation to access Objects, we can access\u2026","rel":"","context":"In &quot;Salesforce&quot;","block_context":{"text":"Salesforce","link":"https:\/\/www.jitendrazaa.com\/blog\/category\/salesforce\/"},"img":{"alt_text":"Setup Audit Trail - Salesforce Winter 16","src":"https:\/\/i0.wp.com\/www.jitendrazaa.com\/blog\/wp-content\/uploads\/2015\/10\/Setup-Audit-Trail.jpg?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.jitendrazaa.com\/blog\/wp-content\/uploads\/2015\/10\/Setup-Audit-Trail.jpg?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/www.jitendrazaa.com\/blog\/wp-content\/uploads\/2015\/10\/Setup-Audit-Trail.jpg?resize=525%2C300&ssl=1 1.5x, https:\/\/i0.wp.com\/www.jitendrazaa.com\/blog\/wp-content\/uploads\/2015\/10\/Setup-Audit-Trail.jpg?resize=700%2C400&ssl=1 2x"},"classes":[]}],"jetpack_likes_enabled":true,"_links":{"self":[{"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/posts\/5042","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/comments?post=5042"}],"version-history":[{"count":14,"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/posts\/5042\/revisions"}],"predecessor-version":[{"id":5560,"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/posts\/5042\/revisions\/5560"}],"wp:attachment":[{"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/media?parent=5042"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/categories?post=5042"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/tags?post=5042"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}