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
Sumant HegdeSumant Hegde 

Not able to display list of item in public sites

Hi,

I am trying to display list of records retrieve from SOQL query in my public site.
Tried using <apex:PageBlockTable> and <apex:repeat>. Both work fine when I "preview" it using developer console, but the value will not be displayed on the public site that I have created.

Does it have anything to do with permissions?

Thanks,
Steven NsubugaSteven Nsubuga
Well, the public site has its own User and its own Profile that need to be given access to your Visualforce page and Controller. Access the User and Profile via the Public Access Settings of the site.
Sumant HegdeSumant Hegde
Hi Steven,

Thanks for your suggestion.
I have given all the access permission to the guest user in "Public Access Setting'.
Issue is like this
When I use <apex:pageBlockTable> or <apex:repeat> tags, the public site displays the number of rows according to the list size, but the rows will not display any values in it.

I am not sure, what permission/access issue is causing this.
 
Steven NsubugaSteven Nsubuga
Did you grant the Profile access to your object (object level security) and all its fields (field level security)?
Sumant HegdeSumant Hegde
Yes. I am able to display single value on the page, but when i try to dislay the list of items, it is not working.

Example1:
This code works. I can display the value of lastName in my vf page.

---------------------------controller-------------------------------------
public class display{

    public List<cust_obj__c> ab{get;set;}    
    public String lastName{get;set;}
  
    public display(){
        ab = [SELECT First_Name__c ,Last_Name__c FROM cust_obj__c WHERE First_Name__c = 'test'];
        for(Registration__c a:ab){
            lastName = a.Last_Name__c;
        }
    }
}

----------------------------vf code---------------------------------
<apex:page controller="getURLId">
    <apex:pageBlock >
        {!lastName}
    </apex:pageBlock>
</apex:page>


Example2:
This is not working. It gives table with blank rows.

------------------------controller----------------------------------
public class display{

    public List<cust_obj__c> ab{get;set;}    
    public String lName{get;set;}
  
    public display(){
        ab = [SELECT First_Name__c ,Last_Name__c FROM cust_obj__c WHERE First_Name__c = 'test'];
    }
}

----------------------------vf code----------------------------------------------
<apex:page controller="getURLId">
    <apex:pageBlock > 
      <apex:pageBlockTable value="{!ab}" var="item">
          <apex:column value="{!item.First_Name__c}"/>
          <apex:column value="{!item.Last_Name__c}"/>
      </apex:pageBlockTable>
    </apex:pageBlock>
</apex:page>
Steven NsubugaSteven Nsubuga
The first example merely displays a String from the controller, that is why it works.
The second example works directly with the object and its fields. Which leads me to ask you to check Field Level Security for that Site Profile.
Sumant HegdeSumant Hegde
Hi Steven,

I just checked the Field-Level Security for site profile with respect to the custom object. All the fields have been given read-access and some are given with write access also.
 
Steven NsubugaSteven Nsubuga
So now I have a dumb question,
are you using the right controller? <apex:page controller="getURLId"> means that the name of your controller is getURLId. However, the class you shared is called display.
Is that right? 
I would go with 
<apex:page controller="display">
    <apex:pageBlock > 
      <apex:pageBlockTable value="{!ab}" var="item">
          <apex:column value="{!item.First_Name__c}"/>
          <apex:column value="{!item.Last_Name__c}"/>
      </apex:pageBlockTable>
    </apex:pageBlock>
</apex:page>

 
Sumant HegdeSumant Hegde
Hi Steven,

Yes I am using right controller. I didn't want to paste my exact code in here, so i changed some of the names while pasting the code. 
But in my code, controller name is "getURLId".
 
Steven NsubugaSteven Nsubuga
I am stumped!! I have applied the code to a site in my sandbox and it worked well for me.

Controller
public class display{

    public List<Individual_Registration__c > ab{get;set;}    
  
    public display(){
        ab = [SELECT Name, Work_Status__c FROM Individual_Registration__c];
    }
}
Visualforce page
<apex:page controller="display">
    <apex:pageBlock > 
      <apex:pageBlockTable value="{!ab}" var="item">
          <apex:column value="{!item.Name}"/>
          <apex:column value="{!item.Work_Status__c }"/>
      </apex:pageBlockTable>
    </apex:pageBlock>
</apex:page>
I still think it is a permissions issue on your end. Sorry I have not been much help.
 
Sumant HegdeSumant Hegde
Hi Steven,

Yes, I also feel that it is permission issue, but I am not able to find out what is that.

I have checked following permissions for my guest user profile
1. Custom Object Permissions for my object "cust_obj__c" and gave Basic access and Data administration permissions
2. Field-level access for the fields of "cust_obj__c" and gave Read and Edit access to all the fields.

Do I need to check any other permissions?
Steven NsubugaSteven Nsubuga
Sharing Settings maybe? Set Organisation Wide Defaults to Public Read/Write
Sumant HegdeSumant Hegde
It is also set to Public Read/Write. :(
Still same issue.
Steven NsubugaSteven Nsubuga

Take a breather and start the final sanity check.

  1. Check that you are modifying the right site's settings.
  2. Check that you are modifying or using the right visualforce page in the site.
  3. The site's profile must have read access to your custom object.
  4. The site's profile must have read access to each of the custom object's fields, checked via Field Level Security of the Site profile.
  5. OWDs set to Public Read/Write.
Good luck!
Sumant HegdeSumant Hegde
Hi Steven,

I have done all these checks and everything is exactly same as you said.
Unfortunately, the issue is still the same.

Thanks
Sumant HegdeSumant Hegde
Hi Steven,

You were right. After lot of research, i found that even though i have given all these permissions, "View All Data" under Org-Wide Permissions, for the guest user profile is not getting selected because of which I am not able to see the data on public site.

Unfortunately, I didn't find any way to mark "View All Data" checkbox for the guest user.
I am trying all these in my salesforce developer edition.

Could you please let me know where can I cnage this permissions?
 
Steven NsubugaSteven Nsubuga
In the Profile, after selecting Public Access Settings, select  View All for your object. Modify All can also be selected if you need it.
My object is called Apex, see below.
View All
Sumant HegdeSumant Hegde
Hi Steven,

I have done that also. 
I am using "Registration" object and the permssion looks like this.

User-added image

Even though I have saved these permissions, if I go to "Sharing setting" and look check the profile permissions, it looks like this.
"Register Profile" is a guest user profile which I have created for my public site. For that user Org-wide permissions are not selected even though I have given the permissions as I showed above.

User-added image
 
Steven NsubugaSteven Nsubuga
Your  screen shot looks like below, so that is not the issue. My site profile is called displayM Profile.
User-added image
 
Sumant HegdeSumant Hegde
Then what else do you think is an issue? Because I tried everything you suggested, but didn't work for me.
Steven NsubugaSteven Nsubuga
Any chance you could get me a log in to your developer org? I think I need to take a look.
My email address is stebugz@gmail.com.