I am using Salesforce Tooling API for creating dynamic VF pages . Everything is fine but i am getting

18:23:09:159 USER_DEBUG [239]|DEBUG|[{"message":"Unexpected character ('P' (code 80)): was expecting comma to separate OBJECT entries at [line:1, column:84]","errorCode":"JSON_PARSER_ERROR"}]

I tried escaping the double quotes , but still cannot fix it . Can anyone help me in this issue . Below is the code am using

String VFPageBody = '<apex:page standardController=\"'+sObjectAPIName+'" extensions=\"ctrlSobjHandler\">\n'
                    + ' <c:SampleComponent sobj=\"{!sobjType}\" rtype=\"{!rtypeName}\"></c:Progress_Meter>\n' 
                    + ' </apex:page>';
    HTTPRequest reqCreateVFPage = new HTTPRequest();
    reqCreateVFPage.setEndpoint(baseUrl + 'sobjects/ApexPage');
    // OAuth header
    reqCreateVFPage.setHeader('Authorization', 'Bearer ' +         UserInfo.getSessionId());
    reqCreateVFPage.setHeader('Content-Type', 'application/json');

    String pageBody = '{"Name" : "'+sObjectName+'HandlerPage" , "Markup" : "'+VFPageBody+'" ,  "MasterLabel" : "'+sObjectName+'HandlerPage" , "ApiVersion" : "29.0" }';

    Http h2 = new Http();
    HttpResponse resCreateVFPage = h2.send(reqCreateVFPage);
    // Response to a create should be 201
    if (resCreateVFPage.getStatusCode() != 201) {
      //  throw new Exception(res.getStatus());

Let me know if you need any more information . Thanks in Advance !!!


You don't need to escape the double quotes because Apex uses a single quote as a string delimiter.

The best way to create JSON is not by concatenating the string yourself but letting JSON.serialize do that work.

So create an Apex class:

public class Request {
    public String Name;
    public String Markup;
    public String MasterLabel;
    public String ApiVersion;

and assign your values to an instance of that and then call JSON.serialize. That will correctly escape all the string values (e.g. double quotes or new lines) and create valid JSON.

You also have mismatching names in your component element:

<c:SampleComponent ...></c:Progress_Meter>

You can also avoid that problem by using:

<c:SampleComponent ... />
  • Actually it was progress_meter for starting and closing tags also . I just didn't edit correctly here – Pruthvi Raj Mar 21 '16 at 13:39
  • Finally got rid of the error , thanks for the suggestion of "no need of escaping the quotes" . But got some weird error , 19:19:57:245 USER_DEBUG [245]|DEBUG|[{"message":"Object type not accessible. Please check permissions and make sure the object is not in development mode: sObject type 'PMTR__Project__c' is not supported.. Original queryString was: 'SELECT Id FROM PMTR__Project__c WHERE id = '000000000000000'': Markup","errorCode":"FIELD_INTEGRITY_EXCEPTION","fields":["Markup"]}] – Pruthvi Raj Mar 21 '16 at 13:52

Try this :

String pageBody =  '{
    "Name": "' + sObjectName + HandlerPage'",
    "Markup": "' + VFPageBody + '",
    "MasterLabel": "' + sObjectName + HandlerPage'",
    "ApiVersion": "29.0"
} ';

Thanks !!!

  • Thanks for the quick response . But again am getting this response / error . 19:03:00:160 USER_DEBUG [245]|DEBUG|[{"message":"Unexpected character ('P' (code 80)): was expecting comma to separate OBJECT entries at [line:1, column:85]","errorCode":"JSON_PARSER_ERROR"}] By the way my VFPage body is String VFPageBody = '<apex:page standardController=\"PMTR__Project__c\" extensions=\"ctrlSobjHandler\">\n' + ' <c:Progress_Meter sobj=\"{!sobjType}\" rtype=\"{!rtypeName}\"></c:Progress_Meter>\n' + ' </apex:page>'; – Pruthvi Raj Mar 21 '16 at 13:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.