Search code examples
apisalesforceprofilesalesforce-communities

VisualForce Page Data is not visible in site, Data is coming from Mock API


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);

Solution

  • 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