0

I have a lightning app in sfdc, and I have a few custom fields in my app, those fields I configured in a JSON file format and place in a visualforce page. Those configuration settings are changed accordingly when I call this visualforce page in my dev instance through jquery, I got all settings, when I deployed in QA instance I got cors exception. Here my question is does a Visualforce can hold a JSON, so that whenever a new field to be added in my app I just go and change JSON. Here is my settings file looks like placed in visual force page.

<apex:page contentType="application/json; charset=utf-8" showHeader="false" standardStylesheets="false" sidebar="false">
{
  "data": {
    "field": [
      {
        "name": "*****",
        "LastName": "****",

      }     

    ]
  }

}
</apex:page>

or else is there any other approach to get data from visualforce through apex class. Thanks and appreciate your support.

1 Answer 1

0

A CORS exception means that you're calling a different server, and that's not allowed without special considerations. You should change your callout method to use a host-relative URL instead:

$.ajax({url:'/apex/ConfigPage'}).done(function(result) { ... });

You may also want to consider using a Static Resource instead:

$.ajax({url:'{!$Resource.config}'}).done(function(result) { ... });

This would be more appropriate for your use case.


For Apex, you can retrieve the page via PageReference:

PageReference ref = Page.configPage;
String jsonString = ref.getContent();
// ...

In Apex code, you can simply query the Static Resource:

StaticResource config = [SELECT Body FROM StaticResource WHERE Name = 'config'];

You must log in to answer this question.

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