afawcett / apex-toolingapi

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

Unable to cast ApexClass into sobject_x when calling the create method. #31

Closed tquilapratyush closed 8 years ago

tquilapratyush commented 9 years ago

Hi

I'm unable to cast ApexClass list into sObject_x list while calling the create() method. The error that I'm getting when making a callout is: "System.UnexpectedException: Got an unexpected error in callout : null. Contact support with error ID: 552847890-13469 (-979352524)"

Request:

create_element:[apex_schema_type_info=(urn:tooling.soap.sforce.com, true, false), field_order_type_info=(sObjects), sObjects=(sObject_x:[ApexClass=ApexClass:[ApiVersion=33.0, ApiVersion_type_info=(ApiVersion, urn:tooling.soap.sforce.com, null, 0, 1, true), Body=@isTest private class Test_toolingSoapSforceCom {

}, BodyCrc=null, BodyCrc_type_info=(BodyCrc, urn:tooling.soap.sforce.com, null, 0, 1, true), Body_type_info=(Body, urn:tooling.soap.sforce.com, null, 0, 1, true), CreatedBy=null, CreatedById=null, CreatedById_type_info=(CreatedById, urn:tooling.soap.sforce.com, null, 0, 1, true), CreatedBy_type_info=(CreatedBy, urn:tooling.soap.sforce.com, null, 0, 1, true), CreatedDate=null, CreatedDate_type_info=(CreatedDate, urn:tooling.soap.sforce.com, null, 0, 1, true), FullName=Test_toolingSoapSforceCom, FullName_type_info=(FullName, urn:tooling.soap.sforce.com, null, 0, 1, true), Id=null, Id_type_info=(Id, urn:tooling.soap.sforce.com, null, 1, 1, true), IsValid=true, IsValid_type_info=(IsValid, urn:tooling.soap.sforce.com, null, 0, 1, true), LastModifiedBy=null, LastModifiedById=null, LastModifiedById_type_info=(LastModifiedById, urn:tooling.soap.sforce.com, null, 0, 1, true), LastModifiedBy_type_info=(LastModifiedBy, urn:tooling.soap.sforce.com, null, 0, 1, true), LastModifiedDate=null, LastModifiedDate_type_info=(LastModifiedDate, urn:tooling.soap.sforce.com, null, 0, 1, true), LengthWithoutComments=null, LengthWithoutComments_type_info=(LengthWithoutComments, urn:tooling.soap.sforce.com, null, 0, 1, true), Metadata=null, Metadata_type_info=(Metadata, urn:tooling.soap.sforce.com, null, 0, 1, true), Name=Test_toolingSoapSforceCom, Name_type_info=(Name, urn:tooling.soap.sforce.com, null, 0, 1, true), NamespacePrefix=null, NamespacePrefix_type_info=(NamespacePrefix, urn:tooling.soap.sforce.com, null, 0, 1, true), Status=Active, Status_type_info=(Status, urn:tooling.soap.sforce.com, null, 0, 1, true), SymbolTable=null, SymbolTable_type_info=(SymbolTable, urn:tooling.soap.sforce.com, null, 0, 1, true), SystemModstamp=null, SystemModstamp_type_info=(SystemModstamp, urn:tooling.soap.sforce.com, null, 0, 1, true), apex_schema_type_info=(urn:tooling.soap.sforce.com, true, false), field_order_type_info=(fieldsToNull, Id, ApiVersion, Body, BodyCrc, CreatedBy, CreatedById, CreatedDate, FullName, IsValid, ...), fieldsToNull=null, fieldsToNull_type_info=(fieldsToNull, urn:tooling.soap.sforce.com, null, 0, -1, true), sObject_x.ApexClass=null, sObject_x.ApexClass_type_info=(ApexClass, urn:tooling.soap.sforce.com, null, 0, 1, true), sObject_x.Id=null, sObject_x.apex_schema_type_info=(urn:tooling.soap.sforce.com, true, false), sObject_x.fieldsToNull=null], ApexClass_type_info=(ApexClass, urn:tooling.soap.sforce.com, null, 0, 1, true), Id=null, apex_schema_type_info=(urn:tooling.soap.sforce.com, true, false), fieldsToNull=null]), sObjects_type_info=(sObjects, urn:tooling.soap.sforce.com, null, 0, -1, false)]

Please could you help.

Thanks Pratyush

tquilapratyush commented 9 years ago

I've just modified few more codes in the class generated from tooling wsdl and now its giving me - "System.CalloutException: Web service callout failed: WebService returned a SOAP Fault: INVALID_TYPE: Must send a concrete entity type. faultcode=sf:INVALID_TYPE faultactor="

Request that I've formed now is:

<?xml version="1.0" encoding="UTF-8"?>env:Header00D24000000JxJC!AR4AQKVFBz8f81yXxdy_ZrddOFNONhEh5_VNKJGiMfjyW0faAMaUfM0KAEimGnVTnsyHOHbCbQcIfRP3tEWj6zm_hVLr8hFm/env:Headerenv:Body33.0@isTest private class Test_toolingSoapSforceCom {}Test_toolingSoapSforceComtrueTest_toolingSoapSforceComActive/env:Body/env:Envelope

Please could you let me know if I'm doing anything wrong. Thanks in advance for your help.

afawcett commented 9 years ago

@dancinllama any thoughts on this?

afawcett commented 9 years ago

@tquilapratyush you may in the meantime want to try out the earlier REST based implementation, which was archived in this branch, https://github.com/afawcett/apex-toolingapi/tree/apex-toolingapi-rest

tquilapratyush commented 9 years ago

Thanks a lot @afawcett This works like a charm..

To provide more info on my issue: Intially, I tried something like: List sObjects = new List(); sObjects = testClassList; ToolingAPIWSDL.SaveResult[] saveResult = toolingAPI.create(sObjects); And, then I tried the following, but both of them gave the same exception – Invalid_Type. List sObjects = new List(); for(ToolingAPIWSDL.ApexClass newTestClass : testClassList) { ToolingAPIWSDL.sObject_x newSObject = new ToolingAPIWSDL.sObject_x(); String[] tempFieldstoNull = new String[]{}; newSObject.fieldsToNull = tempFieldstoNull; //null newSObject.Id = null; newSObject.ApexClass = newTestClass; sObjects.add(newSObject); } ToolingAPIWSDL.SaveResult[] saveResult = toolingAPI.create(sObjects);