3

I have two ways of viewing a VF page.

  1. Through my org with a url like this: https://cseo-dev-ed--seo.na35.visual.force.com/apex/SurveyWelcome?id=a004100000D0mqkAAB

  2. Through a public force.com site that anyone can view through this url: https://surveytest01-developer-edition.na35.force.com/SEO__SurveyWelcome?id=a004100000D0mqk&cntid=0034100000ds6Ia&souceid=0034100000ds6Ia&soucetype=contact

The problem I'm having is my controller is only returning a value when it's accessing the 1st url. When I go to my public force.com site, the apex controller variable doesn't return anything.

Here is the javascript I run when the page loads

<script>
    const images = "{!URLFOR($Resource.img, 'uploads/')}";
    var h = document.getElementsByTagName("html")[0];
    var b = document.getElementsByTagName("body")[0];
    h.style.backgroundImage = `url(${images}{!NewSurvey.SEO__Background_Image__c})`;
    b.style.backgroundImage = `url(${images}{!NewSurvey.SEO__Background_Image__c})`;
    console.log(`{!NewSurvey.SEO__Background_Image__c}`);
</script> 

1st url 1st url

2nd url 2nd url

I'm sure it has something to do with security, but I'm not sure what part of it. My controller for the vf page is public.

3
  • public sites use Guest User profile. Have you granted access of the objects/fields your controller is trying to access to that profile?
    – Mahmood
    May 3, 2017 at 19:00
  • I don't see the Guest User Profile when I go to field level security for the field.
    – Tyler Zika
    May 3, 2017 at 19:02
  • You won't see that there. I think it is related to that issue. Please refer to my answer I am about to post.
    – Mahmood
    May 3, 2017 at 19:04

1 Answer 1

3

Your issue appears to be related to the security and permission on site user. Salesforce Sites uses Guest User profile to allow access to the public users. You need to provide access of your object and / or fields to that profile in order to let the users see the data. To give permissions,

  • Goto Setup
  • Type "Sites"
  • Select the site name (not the URL)
  • You will be redirected to Site configuration page
  • Select configure site
  • Press the Public Access Settings button (that will open the Guest User profile)
  • check if your object with appropriate fields is present there.

That should be it.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .