{"id":5994,"date":"2021-02-09T09:03:46","date_gmt":"2021-02-09T09:03:46","guid":{"rendered":"https:\/\/www.greytrix.com\/blogs\/salesforce\/?p=5994"},"modified":"2021-02-09T09:03:49","modified_gmt":"2021-02-09T09:03:49","slug":"use-of-fls-and-crud-operation-in-salesforce","status":"publish","type":"post","link":"https:\/\/www.greytrix.com\/blogs\/salesforce\/2021\/02\/09\/use-of-fls-and-crud-operation-in-salesforce\/","title":{"rendered":"Use of FLS and CRUD operation in Salesforce"},"content":{"rendered":"\n<p>In this blog, we will understand how to perform FLS and CRUD operation in salesforce. Field-Level Security (FLS) in Salesforce let you restrict users\u2019 access to view and edit specific fields. Field level security implements using the CRUD operation (Create, Read, Update and Delete i.e. CRUD).<\/p>\n\n\n\n<p>Apex in salesforce doesn\u2019t respect CRUD &amp; FLS. It is because most of the processes that a developer has to implement in Apex have to surpass CRUD &amp; FLS.<\/p>\n\n\n\n<p>It is upto the developer to take the responsibility of managing CRUD &amp; FLS in Apex as per requirements. Depending on how your custom applications render and process data, unauthorized users have the potential to access and modify data that they shouldn\u2019t. FLS should be enforced always.<\/p>\n\n\n\n<p>The <a rel=\"noreferrer noopener\" href=\"https:\/\/developer.salesforce.com\/docs\/atlas.en-us.apexcode.meta\/apexcode\/apex_methods_system_sobject_describe.htm\" target=\"_blank\">DescribeSObjectResult class<\/a> includes a number of helper functions. This function can be used for verifying users level of access and prevent data from being inadvertently exposed or modified.<\/p>\n\n\n\n<p>To enforce \u201cdelete\u201d access restrictions, use the <strong><em>isDeleteable()<\/em><\/strong> function before your code performs a delete database operation. If we know specific object name then we can directly performs delete operation using object name as shown in the below code snippet.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>if (Opportunity.sObjectType.getDescribe().isDeleteable())\r\n{\r\ndelete Objoppor;\r\n}\r<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\"><strong><em>Implementation\/Usage:<\/em><\/strong><\/h3>\n\n\n\n<p>If we want to perform any FLS operation in batch class or any other class where we don\u2019t know exact object name then we can \u00a0take object name dynamically as shown in the below code.<\/p>\n\n\n\n<p>First check whether scope is empty or null and check Object type using getSObjectType() function.<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><strong>GetSObjectType():<\/strong> Returns the token for this SObject. This method is used to describe information.<\/li><\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>Global void execute (Database.BatchableContext bc, List&lt;SObject> scope)\r\n{\r\n\tif(scope == null || scope.isEmpty())\r\n    return;\r\n\r\n    SObjectType myType = scope&#91;0].getSObjectType();\r\n    if (myType.getDescribe().isDeletable()==true)\r\n\t{\r\n\t\tdelete scope;\r\n\t}\r\n\telse\r\n\t{\r\n\t\tsystem.debug('You have no permission to delete this object: ' + myType);\r\n\t}\r\n}<\/code><\/pre>\n\n\n\n<p><strong><em>Please Note-<\/em><\/strong> Since you delete records in SOQL and do not delete fields, you need to check only the user\u2019s CRUD access to the object.<\/p>\n\n\n\n<p>We hope you may find this Blog resourceful and helpful. If you still have concerns and need more help, please contact us at <a href=\"mailto:salesforce@greytrix.com\">salesforce@greytrix.com<\/a>.<\/p>\n\n\n\n<p style=\"text-align: justify\"><b>About Us<\/b><\/br>\n<p><a href=\"https:\/\/www.greytrix.com\/\">Greytrix<\/a> \u2013 a globally recognized and one of the oldest Sage Development Partner and a Salesforce Product development partner offers a wide variety of integration products and services to the end users as well as to the Partners and Sage PSG across the globe. We offer Consultation, Configuration, Training and support services in out-of-the-box functionality as well as customizations to incorporate custom business rules and functionalities that require apex code incorporation into the Salesforce platform.<br><br> Greytrix has some unique solutions for Cloud CRM such as <a href=\"\">Salesforce Sage integration<\/a> for <a href=\"https:\/\/www.greytrix.com\/sage-x3-erp\/integration\/\">Sage X3<\/a>, <a href=\"https:\/\/www.greytrix.com\/salesforce-cloud-services\/sage-100-integration\/\">Sage 100<\/a> and <a href=\"https:\/\/www.greytrix.com\/salesforce-cloud-services\/sage-300-integration\/\">Sage 300 (Sage Accpac)<\/a>. We also offer best-in-class Cloud CRM <a href=\"https:\/\/www.greytrix.com\/salesforce-cloud-services\/crm-development\/\">Salesforce customization and development services<\/a> along with services such as Salesforce <a href=\"https:\/\/www.greytrix.com\/salesforce-cloud-services\/data-migration-support\/\">Data Migration<\/a>, <a href=\"https:\/\/www.greytrix.com\/salesforce-cloud-services\/crm-development\/\">Integrated App development<\/a>, Custom App development and Technical Support business partners and end users. Salesforce Cloud CRM integration offered by Greytrix works with Lightning web components and supports standard opportunity workflow. Greytrix GUMU&#x2122; integration for Sage ERP \u2013 Salesforce is a 5-star rated app listed on <a href=\"https:\/\/appexchange.salesforce.com\/appxListingDetail?listingId=a0N30000000psM5EAI\" target=\"_blank\" rel=\"noopener\">Salesforce AppExchange<\/a>.<br> The GUMU&#x2122; Cloud framework by Greytrix forms the backbone of cloud integrations that are managed in real-time for processing and execution of application programs at the click of a button.<br><br> For more information on our Salesforce products and services, contact us at <a href=\"mailto:salesforce@greytrix.com\">salesforce@greytrix.com<\/a>. We will be glad to assist you.<\/p>\n\n\n\n<p><strong>Related Posts<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><a href=\"https:\/\/www.greytrix.com\/blogs\/salesforce\/2021\/01\/22\/salesforce-how-to-get-row-index-of-lightning-table-rows\/\" target=\"_blank\" rel=\"noreferrer noopener\">Salesforce \u2013 How to get row index of lightning table rows<\/a><\/li><li><a href=\"https:\/\/www.greytrix.com\/blogs\/salesforce\/2021\/01\/20\/how-to-add-lightning-web-components-as-custom-tabs-in-salesforce\/\" target=\"_blank\" rel=\"noreferrer noopener\">How to add Lightning Web Components as Custom Tabs in Salesforce<\/a><\/li><li><a href=\"https:\/\/www.greytrix.com\/blogs\/salesforce\/2021\/01\/12\/promote-update-salesforce-contact-to-sage-100-using-gumu-lightning-interface\/\" target=\"_blank\" rel=\"noreferrer noopener\">Promote\/Update Salesforce Contact to Sage 100 using GUMU&#x2122; Lightning Interface<\/a><\/li><li><a href=\"https:\/\/www.greytrix.com\/blogs\/salesforce\/2020\/12\/30\/how-to-activate-and-add-salesforce-lightning-component-on-community-experience\/\" target=\"_blank\" rel=\"noreferrer noopener\">How to Activate and Add Salesforce Lightning component on Community experience<\/a><\/li><li><a href=\"https:\/\/www.greytrix.com\/blogs\/salesforce\/2020\/12\/29\/salesforce-webservice-patch-method-http-patch-verb-in-salesforce\/\" target=\"_blank\" rel=\"noreferrer noopener\">Salesforce Webservice Patch Method \u2013 HTTP PATCH verb in Salesforce<\/a><\/li><\/ul>\n","protected":false},"excerpt":{"rendered":"<p>In this blog, we will understand how to perform FLS and CRUD operation in salesforce. Field-Level Security (FLS) in Salesforce let you restrict users\u2019 access to view and edit specific fields. Field level security implements using the CRUD operation (Create, Read, Update and Delete i.e. CRUD). Apex in salesforce doesn\u2019t respect CRUD &amp; FLS. It\u2026 <span class=\"read-more\"><a href=\"https:\/\/www.greytrix.com\/blogs\/salesforce\/2021\/02\/09\/use-of-fls-and-crud-operation-in-salesforce\/\">Read More &raquo;<\/a><\/span><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[16,18,883,1056,768,1060,1055,1057,861],"class_list":["post-5994","post","type-post","status-publish","format-standard","hentry","category-salesforce-srv","tag-apex-in-salesforce","tag-apex-methods","tag-crud-operations","tag-custom-data-table","tag-field-permissions","tag-fls","tag-lightning-aura-component","tag-lightning-dyanamic-table","tag-salesforce-field-level-security"],"_links":{"self":[{"href":"https:\/\/www.greytrix.com\/blogs\/salesforce\/wp-json\/wp\/v2\/posts\/5994","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.greytrix.com\/blogs\/salesforce\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.greytrix.com\/blogs\/salesforce\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.greytrix.com\/blogs\/salesforce\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.greytrix.com\/blogs\/salesforce\/wp-json\/wp\/v2\/comments?post=5994"}],"version-history":[{"count":2,"href":"https:\/\/www.greytrix.com\/blogs\/salesforce\/wp-json\/wp\/v2\/posts\/5994\/revisions"}],"predecessor-version":[{"id":5996,"href":"https:\/\/www.greytrix.com\/blogs\/salesforce\/wp-json\/wp\/v2\/posts\/5994\/revisions\/5996"}],"wp:attachment":[{"href":"https:\/\/www.greytrix.com\/blogs\/salesforce\/wp-json\/wp\/v2\/media?parent=5994"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.greytrix.com\/blogs\/salesforce\/wp-json\/wp\/v2\/categories?post=5994"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.greytrix.com\/blogs\/salesforce\/wp-json\/wp\/v2\/tags?post=5994"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}