You need to sign in to do that
Don't have an account?
Hitendra Sabhadiya
How to set Field-Level security for Profile from Apex class ?
I want to set field level security for particular field of object from Apex.
e.g There is custom field named "SLASerialNumber__c" on Account object and I have System Administrator Profile.
So I want to give Read and Edit Access of field to Profile.
How it's possible?
e.g There is custom field named "SLASerialNumber__c" on Account object and I have System Administrator Profile.
So I want to give Read and Edit Access of field to Profile.
How it's possible?
Please try this.
For a Specific Profile: For Current User: Please let us know if you need anything else.
Thanks,
Nagendra
All Answers
Please try this.
For a Specific Profile: For Current User: Please let us know if you need anything else.
Thanks,
Nagendra
I am not sure.
but,I think that solution which you have provided is to check field level security for perticular field.
I can't set FLS for field from apex.
Hi Hitendra,
You can get field permissions and set each permission by setting them to 'true'/'false'.
Adding sample code for setting permissions for each field of opportunity sobject and you can check for profile by adding below query to list rt query.
AND Parent.ProfileId IN (SELECT Id FROM PermissionSet WHERE PermissionSet.Profile.Name = 'System Administrator').
You can also refer to https://developer.salesforce.com/forums/?id=906F00000005HTsIAM.Hope this ans helps you, if it does select it as best answer.
Shubham Nandwana.
AppPerfect Corp.
salesforce@appperfect.com
408-252-4100
http://www.appperfect.com/services/salesforce/
Salesforce Development & Operations Experts
Please see below query. Hope this helps you.
Here is how you can get the Field Level Security for particular profile:
SELECT Id, Field, SObjectType, PermissionsRead, PermissionsEdit FROM FieldPermissions WHERE parentid in (select id from permissionset where PermissionSet.Profile.Name = 'System Administrator')
You can restrict the number of records by looking at a specific sObject. Ex:
SELECT Id, Field, SObjectType, PermissionsRead, PermissionsEdit FROM FieldPermissions WHERE SObjectType = 'Opportunity' and parentid in (select id from permissionset where PermissionSet.Profile.Name = 'System Administrator')
Also, go through the below link also.
https://welkinsuite.com/blog/salesforce-permissions-applied-to-apex/
Please mark it as best answer if it helps you.
Thank You,
Ajay Dubedi
Do you have code above code in java? I have created custom fields using meta data api but not able to set the field level security and not able to add in custom page layout. Can you tell me how to assign the custom field to the existing profile so that it can be added to the layout?
I have created a field through Apex.But System Administrator also didn't get even the read access on that field.
Does anybody help to grant read and edit access for all the users through Apex ?