0

I am trying to get the Sobject Name by prefix of Id using below query in my JAVA code:

        QueryResult queryResultsAttach = conn 
            .query("Select Id,QualifiedApiName,KeyPrefix from EntityDefinition where KeyPrefix = '001' limit 1 ");
    SObject[] entityDefinition = queryResultsAttach.getRecords();
    Object apiName = entityDefinition[0].getField("QualifiedApiName");
    System.out.println("entityDefinition "+apiName);

This is throwing an error -

Exception in thread "main" [InvalidSObjectFault [ApiQueryFault [ApiFault exceptionCode='INVALID_TYPE' exceptionMessage='sObject type 'EntityDefinition' is not supported.' ] row='-1' column='-1' ] ]

I ran the query in dev console using the same credentials and the query returned a record. Even hardcoded the id in query in my java program but still getting this error. Any ideas what could be missing?

  • Have you checked the API version. It is supported after version 32. – Tushar Sharma Oct 9 '17 at 6:16
  • Yes.. it says Salesforce.com Tooling API version 40.0 – Anisa Oct 9 '17 at 6:19
  • Though the Tooling API WSDL said v41.0, my service endpoint had a different version. Changed to 41.0 and it worked fine. Thank you! – Anisa Oct 12 '17 at 6:23
0

Double or triple check your API version. The response you are getting is exactly what you get with EntityDefiniton when you use API v31.0 or earlier.

SOAP Tooling API query to https://na87.salesforce.com/services/Soap/T/31.0/00D300000000001

Request

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn="urn:tooling.soap.sforce.com">
   <soapenv:Header>
      <urn:SessionHeader><urn:sessionId>00D30000000023456!AQ0AQIoLpcG6nREALSESSIONIDh9tFHVRr0iM3Q2iej8UZvlDNjKN</urn:sessionId>
      </urn:SessionHeader>
   </soapenv:Header>
   <soapenv:Body>
      <urn:query>
         <urn:queryString>Select Id,QualifiedApiName,KeyPrefix from EntityDefinition where KeyPrefix = '001' limit 1</urn:queryString>
      </urn:query>
   </soapenv:Body>
</soapenv:Envelope>

Response

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:sf="urn:tooling.soap.sforce.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
   <soapenv:Body>
      <soapenv:Fault>
         <faultcode>sf:INVALID_TYPE</faultcode>
         <faultstring>INVALID_TYPE: sObject type 'EntityDefinition' is not supported.</faultstring>
         <detail>
            <sf:InvalidSObjectFault xsi:type="sf:InvalidSObjectFault">
               <sf:exceptionCode>INVALID_TYPE</sf:exceptionCode>
               <sf:exceptionMessage>sObject type 'EntityDefinition' is not supported.</sf:exceptionMessage>
               <sf:row>-1</sf:row>
               <sf:column>-1</sf:column>
            </sf:InvalidSObjectFault>
         </detail>
      </soapenv:Fault>
   </soapenv:Body>
</soapenv:Envelope>

Same thing against v32.0.

Response

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:sf="urn:tooling.soap.sforce.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
   <soapenv:Body>
      <soapenv:Fault>
         <faultcode>sf:INVALID_FIELD</faultcode>
         <faultstring>INVALID_FIELD: 
Select Id,QualifiedApiName,KeyPrefix from EntityDefinition
                           ^
ERROR at Row:1:Column:28
No such column 'KeyPrefix' on entity 'EntityDefinition'. If you are attempting to use a custom field, be sure to append the '__c' after the custom field name. Please reference your WSDL or the describe call for the appropriate names.</faultstring>
         <detail>
            <sf:InvalidFieldFault xsi:type="sf:InvalidFieldFault">
               <sf:exceptionCode>INVALID_FIELD</sf:exceptionCode>
               <sf:exceptionMessage>Select Id,QualifiedApiName,KeyPrefix from EntityDefinition
                           ^
ERROR at Row:1:Column:28
No such column 'KeyPrefix' on entity 'EntityDefinition'. If you are attempting to use a custom field, be sure to append the '__c' after the custom field name. Please reference your WSDL or the describe call for the appropriate names.</sf:exceptionMessage>
               <sf:row>1</sf:row>
               <sf:column>28</sf:column>
            </sf:InvalidFieldFault>
         </detail>
      </soapenv:Fault>
   </soapenv:Body>
</soapenv:Envelope>

Then it starts working from v33.0 onwards:

Response

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns="urn:tooling.soap.sforce.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
   <soapenv:Body>
      <queryResponse>
         <result>
            <done>true</done>
            <entityTypeName>EntityDefinition</entityTypeName>
            <queryLocator xsi:nil="true"/>
            <records xsi:type="EntityDefinition">
               <Id>4ie1W00001000GkQAI</Id>
               <KeyPrefix>001</KeyPrefix>
               <QualifiedApiName>Account</QualifiedApiName>
            </records>
            <size>1</size>
            <totalSize>1</totalSize>
         </result>
      </queryResponse>
   </soapenv:Body>
</soapenv:Envelope>
| improve this answer | |
  • Though the Tooling API WSDL said v41.0, my service endpoint had a different version. Changed to 41.0 and it worked fine. Thank you! – Anisa Oct 12 '17 at 6:23

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.