Activity Forums Salesforce® Discussions How to get Salesforce Visualforce page output as JSON?

  • shariq

    Member
    September 22, 2018 at 5:01 pm

    <apex:page controller="ControllerName" contentType="application/x-JavaScript; charset=utf-8" showHeader="false" standardStylesheets="false" sidebar="false">
    {!jsonString}
    </apex:page>

  • Parul

    Member
    September 22, 2018 at 5:49 pm

    Output Visualforce page as JSON Data:

    To output the Visualforce page as JSON Data following point needs to be taken care,

    contentType should be “application/x-JavaScript; charset=utf-8” (Note that i have not specified it as json although valid MIME type available for JSON in HTML)
    showHeader attribute should be false.
    standardStylesheets attribute should be false.
    sidebar attribute should be false.
    While calling the VF page always specify explicitly that we don’t need Page editor tool of the Salesforce using core.apexpages.devmode.url=0.
    Source code for VF:

    <apex:page controller="GanttChartData"  contentType="application/x-JavaScript; charset=utf-8" showHeader="false" standardStylesheets="false" sidebar="false">
    {!jsonString}

    </apex:page>

  • Parul

    Member
    September 22, 2018 at 6:01 pm

    <apex:page controller="JSONGenerator" contentType="application/json; charset=utf-8" showHeader="false" standardStylesheets="false" sidebar="false">
    {!jsonStr}
    </apex:page>

Log In to reply.

Popular Salesforce Blogs

Popular Salesforce Videos