afawcett / apex-toolingapi

Apex wrapper for the Salesforce Tooling API
BSD 3-Clause "New" or "Revised" License
134 stars 98 forks source link

Invalid conversion from runtime type List<ToolingAPIWSDL.sObject_x> to List<ToolingAPIWSDL.CustomObject> #36

Closed rdehler closed 9 years ago

rdehler commented 9 years ago

I tried to convert this sample to using the WSDL: http://andyinthecloud.com/2014/01/05/querying-custom-object-and-field-ids-via-tooling-api/

    String objectName = 'Job_Activity';
    String fieldName = 'Order_Line';
    ToolingAPI toolingAPI = new ToolingAPI();
    List<ToolingAPIWSDL.CustomObject> customObjects = (List<ToolingAPIWSDL.CustomObject>)
        toolingAPI.query('Select Id, DeveloperName, NamespacePrefix From CustomObject Where DeveloperName = \''+objectName+'\'').records;

    ToolingAPIWSDL.CustomObject customObject = customObjects[0];
    Id customObjectId = customObject.Id;
    List<ToolingAPIWSDL.CustomField> customFields = (List<ToolingAPIWSDL.CustomField>)
         toolingAPI.query('Select Id, DeveloperName, NamespacePrefix, TableEnumOrId From CustomField Where DeveloperName = \''+fieldName+'\' and TableEnumOrId = \'' + customObjectId + '\'').records;

Upon trying to run this, I get:

 Invalid conversion from runtime type List<ToolingAPIWSDL.sObject_x> to List<ToolingAPIWSDL.CustomObject>

Am I missing something obvious?

rdehler commented 9 years ago

Replace with this and it works, FYI @afawcett

    List<ToolingAPIWSDL.sObject_x> customObjects = (List<ToolingAPIWSDL.sObject_x>)
        toolingAPI.query('Select Id, DeveloperName, NamespacePrefix From CustomObject Where DeveloperName = \''+objectName+'\'').records;

    ToolingAPIWSDL.sObject_x customObject = customObjects[0];
    Id customObjectId = customObject.Id;
    List<ToolingAPIWSDL.sObject_x> customFields = (List<ToolingAPIWSDL.sObject_x>)
         toolingAPI.query('Select Id, DeveloperName, NamespacePrefix, TableEnumOrId From CustomField Where DeveloperName = \''+fieldName+'\' and TableEnumOrId = \'' + customObjectId + '\'').records;
afawcett commented 9 years ago

Thanks @rdehler, speaking with @dancinllama recently we feel we may want to return to the REST API wrapper approach, now that it appears to support bulk. Sorry for the confusion in the meantime.