{"id":56,"date":"2011-05-21T11:28:23","date_gmt":"2011-05-21T06:28:23","guid":{"rendered":"http:\/\/learnsf.wordpress.com\/?p=56"},"modified":"2011-05-21T11:28:23","modified_gmt":"2011-05-21T06:28:23","slug":"disable-validation-rules-4-data-load","status":"publish","type":"post","link":"https:\/\/blog.felineflock.com\/index.php\/2011\/05\/21\/disable-validation-rules-4-data-load\/","title":{"rendered":"How to disable\/enable all validation rules for data loading"},"content":{"rendered":"<p>While working on a recruiting application, I found a solution for being able to load data into a SalesForce application without being blocked by validation rules.<\/p>\n<p>Validation rules are usually intended to be applied only when a user creates a record and not when data is being imported from an external database. In this recruiting application, candidate records go several stages in a sequence (1-lead, 2-phone, 3-applicant, 4-interview, 5-contract negotiation, etc.) and this validation rule prevented the import process from loading candidate records in a stage higher than lead.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignright size-full wp-image-57\" title=\"AppSetupCustomSettings\" src=\"http:\/\/blog.felineflock.com\/wp-content\/uploads\/2011\/05\/appsetupcustomsettings.jpg\" alt=\"\" width=\"104\" height=\"153\" \/><\/p>\n<p>So the solution was to create a Custom Setting of type Hierarchy with a flag\/checkbox in it that disables validation rules for a given user or profile. That is, all the validation rules will include this flag and only\u00a0apply\u00a0when\u00a0the value of this flag is enabled.<\/p>\n<p>To implement it:<\/p>\n<p>1) click Setup, then on the left side, click App Setup\/Develop\/Custom Settings.<\/p>\n<p>2) click New and create your settings as hierarchy\/public<\/p>\n<p style=\"text-align:center;\"><a href=\"http:\/\/blog.felineflock.com\/wp-content\/uploads\/2011\/05\/appsetupcustomsettings2.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"size-medium wp-image-58 aligncenter\" title=\"AppSetupCustomSettings2\" src=\"http:\/\/blog.felineflock.com\/wp-content\/uploads\/2011\/05\/appsetupcustomsettings2.jpg?w=300\" alt=\"\" width=\"300\" height=\"193\" srcset=\"https:\/\/blog.felineflock.com\/wp-content\/uploads\/2011\/05\/appsetupcustomsettings2.jpg 516w, https:\/\/blog.felineflock.com\/wp-content\/uploads\/2011\/05\/appsetupcustomsettings2-300x193.jpg 300w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>3) now create a custom field of type Checkbox: \u00a0click New, select Checkbox, click Next, type the name of the field as &#8220;Disable Validation Rules&#8221;, default to Unchecked, click Next, then click Save.<\/p>\n<p>4) in the Custom Setting Definition\/Your App Settings screen, click Manage to start configuring the setting you just created.<\/p>\n<p>5) click the New button above &#8220;Default Organization Level Value&#8221;, leave the checkbox &#8220;Disable Validation Rules&#8221; unchecked and then click Save.<\/p>\n<p>6) click &#8220;Back to List&#8221;, click the New button at the bottom, select Profile or User then choose the user id or profile that will perform the data loading, then click &#8220;Disable Validation Rules&#8221; and click Save.<\/p>\n<p>7) now edit the validation rule appending the expression (highlighted below)<br \/>\n<strong>&amp;&amp; NOT( $Setup.Your_App_Settings__c.Disable_Validation_Rules__c )<\/strong><\/p>\n<p><a href=\"http:\/\/blog.felineflock.com\/wp-content\/uploads\/2011\/05\/appsetupcustomsettings3.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignleft size-medium wp-image-59\" title=\"AppSetupCustomSettings3\" src=\"http:\/\/blog.felineflock.com\/wp-content\/uploads\/2011\/05\/appsetupcustomsettings3.jpg?w=300\" alt=\"\" width=\"300\" height=\"257\" srcset=\"https:\/\/blog.felineflock.com\/wp-content\/uploads\/2011\/05\/appsetupcustomsettings3.jpg 519w, https:\/\/blog.felineflock.com\/wp-content\/uploads\/2011\/05\/appsetupcustomsettings3-300x258.jpg 300w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a>\u00a0 8 ) click Save<\/p>\n<p>9) now the validation rule will only apply if the setting checkbox<br \/>\nDisable Validation Rules is unchecked for your profile\/user<\/p>\n<p>10) you can now load data freely and then, later, re-enable all<br \/>\nvalidation rules for your profile\/user by changing the custom<br \/>\nsetting.<\/p>\n<p>11) you can use this way of implementing Custom Settings on<br \/>\ntriggers too, just use the syntax below:<\/p>\n<pre> Your_App_Settings__c s =\u00a0\n Your_App_Settings__c.getInstance( UserInfo.GetUserID() );<span style=\"color:#339966;\"> \/\/or <var>Profile<\/var><\/span>\n if( s.Disable_Validation_Rules__c ) return;<span style=\"color:#008000;\"><em> \/\/ skip trigger...<\/em><\/span><\/pre>\n<p>Pertinent Articles:<br \/>\n&#8211;\u00a0<a href=\"http:\/\/www.peteyg.com\/SFDC\/HT\/cs_accessing.htm\" target=\"_blank\" rel=\"noopener\">Accessing Custom Settings<\/a><br \/>\n&#8211; <a href=\"http:\/\/forcebehindtheforce.com\/2011\/03\/18\/lets-make-some-magic\/\">Let&#8217;s make some magic&#8230;<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>While working on a recruiting application, I found a solution for being able to load data into a SalesForce application without being blocked by validation rules. Validation rules are usually intended to be applied only when a user creates a record and not when data is being imported from an external database. In this recruiting [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"_uf_show_specific_survey":0,"_uf_disable_surveys":false,"footnotes":""},"categories":[8,18],"tags":[],"class_list":["post-56","post","type-post","status-publish","format-standard","hentry","category-data-load","category-validation"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/blog.felineflock.com\/index.php\/wp-json\/wp\/v2\/posts\/56","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.felineflock.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.felineflock.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.felineflock.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.felineflock.com\/index.php\/wp-json\/wp\/v2\/comments?post=56"}],"version-history":[{"count":0,"href":"https:\/\/blog.felineflock.com\/index.php\/wp-json\/wp\/v2\/posts\/56\/revisions"}],"wp:attachment":[{"href":"https:\/\/blog.felineflock.com\/index.php\/wp-json\/wp\/v2\/media?parent=56"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.felineflock.com\/index.php\/wp-json\/wp\/v2\/categories?post=56"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.felineflock.com\/index.php\/wp-json\/wp\/v2\/tags?post=56"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}