2

In my Visualforce Page, I just use the following code to get a name list of contacts that the current user can visit.

public with sharing class TestClass{
    public String getAllContactNames(){
        Contact[] contacts = [SELECT Name FROM Contact];
        String[] res = new List<String>();
        res.add(String.valueOf(count.size()));
        for(Contact c : contacts){
         res.add(c.Name);             
        }
     return String.join(res, '\r\n');
    }
}

The Markup for the VF page is like the following:

<apex:page controller="TestClass">
  <h1>List All Contacts</h1>
     <pre>
        {!AllContactNames}
     </pre>
</apex:page>

It works well with different user with different profiles, and each user can see the possible contacts that he has permission. But when I log-in with a customer community plus user, I can see only several records in this list. Then I tried to visit the standard List View for "All Contacts"(of course with the Customer Community Plus User), I can see more contacts.

We tried with several experiments and we can realize the following:

  • This issue will only occur when the sharing setting of contact be default "Controlled by Parent"
  • We should not user "without sharing",because that will let user see all contacts, and if a contact is not link to any account, it is private, the user without View All permission should not see it. (See:https://success.salesforce.com/answers?id=90630000000gkohAAA)
  • It seems like that when we use "with sharing" in apex code, only the contact that links to the same account with the current user, and the contact owned by this user will be returned.
  • Till now, we only notice the strange behavior with a customer community plus user, for a standard user profile, this issue never occur.

So we are confused now, and we have the following questions: What we should do to get the the same result with the standard list view returned? Or actually the apex code "with sharing" did the correct behavior?

  • See Contact Sharing Rules do not grant users access to Contacts as expected. Do these users have access to the parent accounts? – Adrian Larson Feb 20 '17 at 1:12
  • I think you should narrow down the problem to a specific record. May be take one contact, which you see in the standard list view but not in your query and then compare that contact with another one which is displaying in the list view and your query. Also check this question salesforce.stackexchange.com/questions/153705/… – javanoob Feb 20 '17 at 2:47
  • @javanoob I have already compared the difference. Actually I can access both the contact that does or does not included in the returned value by my code. So I think actually the Community Cloud have permission to access the record that listed in the standard list view. But, why "with sharing" Apex code return limited result? I don't understand. This issue never occurs in a standard salesforce user. Does it because of there is strange result with Community Cloud User? – Leo Li Feb 20 '17 at 3:56
  • @AdrianLarson Thanks for your answer, actually when I try to read all accounts with this user, all Account records can be reached, because the default sharing rule for Account and Contract is Public Read/Write. – Leo Li Feb 20 '17 at 4:05
  • The community might have an easier time assessing this behavior if you share your markup as well. – Adrian Larson Feb 20 '17 at 5:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.