0

Thank you for helping me,

I have created a Visualforce page and the page data is coming from the MOCK API.

I have created a site and add the VisualForce Page in the Site as well under Public Access Settings[Site Profile]

  1. The Page Controller access is also given the to the site profile and all the depended on classes for the API

  2. I have gone through blogs and find out to give access to profile. I have checked all object's which is useless by the way because the data is coming from API, not from a custom object.

I am stuck here can anyone help me, please

Thank you

Http http = new Http();
    HttpRequest request = new HttpRequest();
    request.setHeader('Authorization','Mock'+ UserInfo.getSessionId());
    request.setHeader('Accept', 'application/json');
    request.setEndpoint('https://test.my.salesforce.com/services/apexrest/mockapi/mockapi.json');
    request.setMethod('GET');
    
    HttpResponse response = http.send(request);
Malik
  • 121
  • 1
  • 1
  • 17

1 Answers1

1

Put a debug log on the "[Your Site Name] Guest User" to verify data is really coming in. Yes, there will be a special user for all not logged in access, just like there's Site profile. There might be an error which you don't see if there's no <apex:pageMessages> component (or maybe it's there but you played with rerender attributes and didn't include it).

What do you pass to Visualforce as the API call result? Raw JSON/XML that's then parsed by JavaScript? If you pass a real Apex object parsed out of these - make sure your object has getters/setters like in https://stackoverflow.com/a/63638698/313628

eyescream
  • 18,088
  • 2
  • 34
  • 46
  • Hi yes the wrapper classes are using getter and setter, there in no rerender in the code. – Malik Sep 08 '20 at 11:18
  • So getter setter are there, and when I view the visualforce page it's coming to stand alone and when I add the same vf in the site it's not coming, – Malik Sep 08 '20 at 12:24
  • Not sure what you mean by "stand alone". Viewing as internal user works, as guest doesn't? Controller is added to profile and there are no errors in debug log? Hm, not sure. Can you post some anonymised code? – eyescream Sep 08 '20 at 17:10
  • How do you make the callout? Raw (remote site setting) or with named credential? If with NC - does it include current user's ID or something in authentication options? Can you see on the API side if the callout is made from Site? – eyescream Sep 08 '20 at 17:14
  • Guest users do not log in so they don't really get a session ID. https://help.salesforce.com/articleView?id=000335516&type=1&mode=1. And the Guest user "Profile" might not have "API enabled" ticked. Is this in same org or callout to different one? Any chance you can retrieve the data by making normal apex calls (String jsonBody = SomeClass.someMethod())? – eyescream Sep 08 '20 at 21:08
  • by standalone I mean when I just preview the page, not in the site, but when I view in the site there is not data – Malik Sep 08 '20 at 21:36
  • It's the same Org, so I have checked site profile also the API check is enabled – Malik Sep 08 '20 at 21:40
  • Without valid session id the API call will fail. You'd really have to call it as `SomeClass.someMethod()` returning a value instead of internal REST. – eyescream Sep 08 '20 at 22:16
  • can you please share your email, yes the API is working in VF but the same VF when included in the Site "Not Showing Data" , The API Endpoint is internal also its the class from which we are getting the JSON – Malik Sep 08 '20 at 22:49
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/221180/discussion-between-malik-and-eyescream). – Malik Sep 08 '20 at 22:55