+ Start a Discussion

Record level permission through apex

Hi All


I have a record in account.I want only particular users to see that record and other users should not see it.


Can i achieve this functionality through apex code or is there any way to achieve it


This may not be acheived through Apex. 

What do you want? Record level access OR object level access?


If you want to give object level access, then create a profile in which you keep Account object as private, then attach that profile with the users for whom you want to hide that object data.


If you want record level security then please check the following links




If this post is helpful please throw Kudos.If this post solves your problem kindly mark it as solution.



Use Apex only if this is not possible declaratively.


What you should do first is set the org-wide default sharing for the Account object:



Once that done, only users that are above the account owner in the hierarchy will be able to see it.


You then open up access with Account Sharing Rules:



Account sharing rules can be based on the record owner or on other criteria, including record type and certain field values.

You can give access to specific roles or a pre-defined group of users.


I want further help, I sugggest you provide more details about how you want to share the accounts.




Hi WT35


Actually my requirement is


I have 5 users for my organization .I am saving an account record and I have a text field in account . In each account record I have a multipicklist of users and I select users who want to see the particular text field for the record and only those users should see and others should not be able to see the text field for that particular record.


Now I have saved another record and I chose 2 users in multipicklist and only those 2 users should be able to see the text field of that particular record and others should not see the text field.The same goes for all other account records.How can i ACHIEVE THIS


Yes you can do it without apex code.

1. make Sharing private over it

2. Now create a group and keep all users in that group who need accessiblity of that record

3. Now manually share that record with group.




Hi Sandeep


I got it how to share a individual record with different users but actually I need to share my activity record to users instead of account record but I am unable to see a button like sharing that is visible on account record.Can we do it for activity record as well


This button gets visible when OWD ( organization wide default setting is for object is private) but.  so Please set OWD to private to activity and now check if sharing button is visible on record detail page or not.


if not then please check button on Account related to activities.because there is one more concept that sharing setting  which  controller by parent object in case of Master detail relationship.