3

I have this very simple script on the JSforce script executor:

var apexBody = "<apex:page standardController='Account'>Test</apex:page>";
conn.tooling.sobject('ApexPage').create({
  markup: apexBody,
  name: "PageTest",
  masterlabel: "PageTestLabel"
}, function(err, res) {
  if (err) { return console.error(err); }
  console.log(res);
});

I am in a DE org and logged in as Sys Admin. I recall getting the same error while ago when I tried the Tooling API in Apex:

FIELD_INTEGRITY_EXCEPTION: Object type not accessible. Please check permissions and make sure the object is not in development mode: sObject type 'Account' is not supported.. Original queryString was: 'SELECT Id FROM Account WHERE id = '000000000000000'': Markup

This error only occurs when setting standardController. It seems Tooling API wants to run a query for some reason -and obviously it cannot query non-Tooling objects. Any ideas?

UPDATE: The question was previously referencing a custom object Car__c, but it is now changed to use Account.

2 Answers 2

2

I replicated your jsForce test in a Visualforce page with:

<apex:page docType="html-5.0" showHeader="false">
  <script src="//cdnjs.cloudflare.com/ajax/libs/jsforce/1.4.1/jsforce.min.js"></script>

  <script>
    var apexBody = "<" + "apex:page standardController=\'Account\'>Test" + "<" + "/apex:page>";
    var conn = new jsforce.Connection({ accessToken: '{!$API.Session_Id}' });
    conn.tooling.sobject('ApexPage').create({
      Markup: apexBody,
      Name: "PageTest",
      Masterlabel: "PageTestLabel",
      ControllerType: "1",
      ApiVersion: "33.0"
    }, function(err, res) {
      if (err) { return console.error(err); }
      console.log(res);
    });
  </script>

</apex:page>

Note that I added ControllerType with the value of 1 based on Creating Visualforce Page Using Tooling API.

This resulted in a POST request to https://mynamespace.na17.visual.force.com/services/data/v33.0/tooling/sobjects/ApexPage

With the headers:

  1. Content-Type:application/json
  2. Authorization:Bearer 00Do00000000001!AQ8AQA05qLAXINotMyRealSessionId8v92WE

Payload:

{"Markup":"<apex:page standardController='Account'>Test</apex:page>","Name":"PageTest","Masterlabel":"PageTestLabel","ControllerType":"1","ApiVersion":"33.0"}

I received the same 400 Bad Request response that you did:

[
    {
        "message": "Object type not accessible. Please check permissions and make sure the object is not in development mode: sObject type 'Account' is not supported.. Original queryString was: 'SELECT Id FROM Account WHERE id = '000000000000000'': Markup",
        "errorCode": "FIELD_INTEGRITY_EXCEPTION",
        "fields": [
            "Markup"
        ]
    }
]

Out of interest, I created the ApexPage directly in the Salesforce UI and then retrieved the resulting JSON definition via the Tooling API.

{
    "attributes": {
        "type": "ApexPage",
        "url": "/services/data/v33.0/tooling/sobjects/ApexPage/066o0000002eacAAAQ"
    },
    "Id": "066o0000002eacAAAQ",
    "NamespacePrefix": "DF14DFB",
    "Name": "PageTest",
    "ApiVersion": 33,
    "MasterLabel": "PageTestLabel",
    "Description": null,
    "ControllerType": "1",
    "ControllerKey": "Account",
    "IsAvailableInTouch": false,
    "IsConfirmationTokenRequired": false,
    "Markup": "<apex:page standardController=\"Account\">Test</apex:page>",
    "CreatedDate": "2015-07-06T20:43:55.000+0000",
    "CreatedById": "005o0000001V9OXAA0",
    "LastModifiedDate": "2015-07-06T20:44:53.000+0000",
    "LastModifiedById": "005o0000001V9OXAA0",
    "SystemModstamp": "2015-07-06T20:44:53.000+0000"
}

Stripping out the Dates etc... and changing the Name I still got the original error POSTing this back to create a new ApexClass.

So I'd conclude that this is a bug in the Tooling API. Especially as it works if the standardController isn't defined.

Previously I'd encountered problems with the Tooling API where it couldn't create the initial records (See How do I use the Tooling API to create a new Apex Trigger?). You may need to create the New ApexClass using the standard REST API rather than the Tooling API.

8
  • Appreciate the reply. As you can see in the VF markup the object Car__c has no namespace in front of it, meaning the org I'm developing in is where the object lives. Also as mentioned the status of the object is set to Deployed already. The query without NMSP fails, but works with it. HOWEVER when I use Tooling API in Developer Console both queries fail. When I include NMSP I get: sObject type 'NMSP__Car__c' is not supported. Still not making sense but I thin we're getting somewhere!
    – Mossi
    Jul 3, 2015 at 21:48
  • @user1936026 If the SOQL query without the NMSP__ namespace prefix is failing, then it is likely that the user who is connected to the API doesn't have the required permissions to access that custom object. Jul 4, 2015 at 0:32
  • The queries were executed in Developer Console. If I run them in an Apex class, with or without the NMSP, they work. I know what you are thinking, but I am the system admin. This is a Developer Edition org and I am the only user in it. It seems the inclusion of standardController throws the API off (the script works fine without it).
    – Mossi
    Jul 4, 2015 at 0:53
  • @user1936026 My thinking is that the Tooling API is getting confused about which Car__c should be used. Either the local org custom object or the managed package version. You initial response indicated that "The query without NMSP fails", which makes me think that it can't access the local Car__c. Can you try setting the standardController to another custom object in the org that doesn't have a corresponding record in the managed packages? Jul 4, 2015 at 8:44
  • Setting the standardController even to Account fails! Here's what I think is going on: when standardController is set the Tooling API tries to query for the object (I don't know why) and since the Tooling API is for querying tooling objects only (e.g. ApexClass, ApexPage, etc) it fails. The error that I get when I run the query in Developer Console using Tooling API is identical to the error here. So bottom line, I think this is a bug.
    – Mossi
    Jul 4, 2015 at 11:29
0

A bit old now, but adding here in case anyone comes across the same problem (as I just did).

Long story short, this process is supported using the standard REST API, rather than the Tooling API. The Tooling API docs actually says:

To create a Visualforce page, use the Force.com REST API or the Metadata API.

Found here: https://developer.salesforce.com/docs/atlas.en-us.api_tooling.meta/api_tooling/tooling_api_objects_apexpagemember.htm

So if you just drop the /tooling/ aspect from your endpoint, it should work fine.

Eg. /services/data/v39.0/sobjects/ApexPage/

And post:

{
    "name": "MyPage",
    "masterLabel": "MyPage",
    "markup": "<apex:page standardController=\"Account\"><\/apex:page>",
}

You must log in to answer this question.

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