function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Albert RaulAlbert Raul 

How to put field level security with/without sharing?

Arun Kumar 1141Arun Kumar 1141
Hello Raul,

You can use the SECURITY_ENFORCED clause in your SOQL queries, including subqueries and cross-object relationships while writing Apex code to apply field-level security. 

For example: 
List<Account> accList = [SELECT Id, parent.Name, parent.Website FROM Account WITH SECURITY_ENFORCED];
If you find this answer helpful, please mark it as the best answer.
Thank you.
Prateek Prasoon 25Prateek Prasoon 25
To put field level security with sharing, you need to follow these steps:
Go to Setup and navigate to the object that contains the field you want to restrict access to.
Click on the "Fields" section and select the field you want to restrict access to.
Scroll down to the "Field-Level Security" section and click on "Set Field-Level Security."
Check the boxes for the profiles and permission sets that should have access to the field.
Click "Save" to apply the changes.
To put field level security without sharing, you can follow these steps:
Go to Setup and navigate to the object that contains the field you want to restrict access to.
Click on the "Fields" section and select the field you want to restrict access to.
Scroll down to the "Field-Level Security" section and click on "Set Field-Level Security."
Uncheck the "Visible" and "Editable" checkboxes for all profiles and permission sets.
Click "Save" to apply the changes.

If you find this answer helpful,Please mark it as the best answer.
Albert RaulAlbert Raul
It helped me. Thank you Arun and Prateek