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
Joshua LadleJoshua Ladle 

Using Apex code to restrict community customers' access to certain records in a Custom Object based on criteria in picklist field of that same Custom Object

I've been told by Salesforce that I need to use Apex coding to do this (permission sets, sharing rules/sets, and validation won't work), but I'm am looking for some direction on how to do it.

I have a Custom Object called Properties that is a child to Accounts. My properties are shopping centers in South Florida in Palm Beach, Broward, and Miami-Dade Counties. The counties are values in a picklist field.

I'd like the community users to have visibility access to all the Properties located in each county that is selected in a Picklist (Multi-Select) field that is in the Contacts Object. Currently, without this structure, community users can see all Properties in all 3 counties.

Thanks in advance for any help you can offer. 
Arvind_SinghArvind_Singh
Hello Joshua 

"Using Apex code to restrict community customers' access to certain records in a Custom Object based on criteria in picklist field of that same Custom Object" 

First thing, You can not restrict Access using Permission/Apex or any any other way. Restriction to record level Access will be drived based on Data Model. You need to have Private data model and then open up access based on requirement. 

Also, I am not very clear that What you trying to do here.  "I'd like the community users to have visibility access to all the Properties located in each county that is selected in a Picklist (Multi-Select) field that is in the Contacts Object."  
Do you mean that based on picklist Selected by user Access will be drived ? Please add some more details to your question to help you. 

Thank you !! 
Joshua LadleJoshua Ladle
Hi, Arvind. Thanks for replying and for the direction about needing to restrict record level access based on a private data model and not through permission, Apex, etc. 

To clarify what I'm trying to accomplish. 

Depending on what county or counties a community user desires access to, I would select those counties in a Picklist (Multi-Select) field in the Contacts Object. Then, based on what counties are selected in that picklist field, the community user would have visibility access to the Properties that are in that county. 

Please let me know if you have any other questions. Thank you!  
Joshua LadleJoshua Ladle
Hello, Arvind. Based on what I replied above, do you have any ideas of how I could set this up?
Thank you!
Kiran ChodavadiyaKiran Chodavadiya
Hello joshua

As per Your Requirement mention Above , You want to restrict access for user by selecting counties(piclklist Field) of Showing Properties respective with counties. 
If i am not making mistake to understand your Question then i have some  solution. 
first thing You should create field depandency. Counties As a Controlling Field & properties as a Dependent Field. But As u says Conties is multi-select picklist field then multi-select picklist can be only dependent field.
try to modify conties datatype to picklist from multi-select picklist.

it can help.
Joshua LadleJoshua Ladle
Hi, Kiran. Thanks for replying to my question. This is so community customer users will have record access to properties (custom object and child of Accounts) that are located within a defined county. Maybe I'm not thinking about it correctly, but I'm not sure if using picklist and field dependencies will work. Thanks for the help. Please let me know your thoughts.