function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
DscerDscer 

API create call returns invalid sObject type

I am attempting to create a new Case record using the API, Partner WSDL. I keep getting the following error:
 
sObject type 'sObject' is not supported. If you are attempting to use a custom object, be sure to append the '__c' after the entity name. Please reference your WSDL or the describe call for the appropriate names.
 
I can successfully call create with Account and Contact. I can also successfully call describeSObject with Case as the parameter.
 
Any ideas?
abhi_developerabhi_developer
Hi Dscer,
 
When ever u reference any custom object or its fields u need to append '__c' in the end of it's name.
 
Because account and contact are standard objects they need not to be referenced like that and can be referenced directly.
 
So if u are using any custon object use these conventions it will work 'i think'
 
-Abhishek Singh
DscerDscer
You are correct, when using custom objects you must add the "__c". However, in this situation, I am referencing the Case object, which is a standard object.
SuperfellSuperfell
You think you're using the case object, but your xml request says the type is sObject, not case. That's what the error message is trying to tell you.
DscerDscer
Here is the code I am using. I don't see where the change would occur from "Case" to "sObject".
 
Code:
//this code does not work
        sForce3.sObject acct = new sForce3.sObject();
        acct.type = "Case";
        System.Xml.XmlElement[] att = new System.Xml.XmlElement[7];
        System.Xml.XmlDocument doc = new System.Xml.XmlDocument();
        att[0] = doc.CreateElement("Status"); att[2].InnerText = "Open";
        att[1] = doc.CreateElement("Priority"); att[3].InnerText = "2 (Medium)";
        att[2] = doc.CreateElement("Account"); att[4].InnerText = "001T0000007LeTQIA0";
        att[3] = doc.CreateElement("Contact"); att[5].InnerText = "003T000000GA2OdIAL";
        att[4] = doc.CreateElement("Type"); att[7].InnerText = "Incident";
        att[5] = doc.CreateElement("Subject"); att[10].InnerText = "A problem";
        att[6] = doc.CreateElement("Description"); att[11].InnerText = "This is the problem";
        acct.Any = att;
        sForce3.sObject[] atts = new sForce3.sObject[1];
        atts[0] = acct;
        sForce3.SaveResult[] sr = _sfdc.create(atts);

//this code works
        sForce3.sObject acct = new sForce3.sObject();
        acct.type = "Account";
        System.Xml.XmlElement[] att = new System.Xml.XmlElement[1];
        System.Xml.XmlDocument doc = new System.Xml.XmlDocument();
        att[0] = doc.CreateElement("Name"); att[0].InnerText = "Dan Scerbo Company";
        acct.Any = att;
        sForce3.sObject[] atts = new sForce3.sObject[1];
        atts[0] = acct;
        sForce3.SaveResult[] sr = _sfdc.create(atts);

 

SuperfellSuperfell
What does the actual XML request look like ?
DscerDscer
Here is the xml request from my code. As you can see, the sObject type is still set to "Case":
 
Code:
<—xml version="1.0" encoding="utf-8"–>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
 <soap:Header>
  <SessionHeader xmlns="urn:partner.soap.sforce.com">
   <sessionId>xxxxxxxxxxxxxxx</sessionId>
  </SessionHeader>
 </soap:Header>
 <soap:Body>
  <create xmlns="urn:partner.soap.sforce.com">
   <sObjects>
    <type xmlns="urn:sobject.partner.soap.sforce.com">Case</type>
    <Id xsi:nil="true" xmlns="urn:sobject.partner.soap.sforce.com" />
    <Status xmlns="">Open</Status>
    <Priority xmlns="">2 (Medium)</Priority>
    <Account xmlns="">001T0000007LeTQIA0</Account>
    <Contact xmlns="">003T000000GA2OdIAL</Contact>
    <Type xmlns="">Incident</Type>
    <Subject xmlns="">A problem</Subject>
    <Description xmlns="">This is the problem</Description>
   </sObjects>
  </create>
 </soap:Body>
</soap:Envelope>

 
abhi_developerabhi_developer

Hi Dscer.

here

        att[0] = doc.CreateElement("Status"); att[2].InnerText = "Open";
        att[1] = doc.CreateElement("Priority"); att[3].InnerText = "2 (Medium)";
        att[2] = doc.CreateElement("Account"); att[4].InnerText = "001T0000007LeTQIA0";
        att[3] = doc.CreateElement("Contact"); att[5].InnerText = "003T000000GA2OdIAL";
        att[4] = doc.CreateElement("Type"); att[7].InnerText = "Incident";
        att[5] = doc.CreateElement("Subject"); att[10].InnerText = "A problem";
        att[6] = doc.CreateElement("Description"); att[11].InnerText = "This is the problem";

You are refering "Account" and "Contact" standard fields of "Case" isn't it.

If so, Use "AccountID" and "ContactID" instead and see if it works.

Do reply as i have some  more inputs.

-Abhishek Singh

DscerDscer

I changed the Account and Contact field names to AccountId and ContactId and that fixed the problem.

I think that the error message returned in this instance is mis-leading. In the past, when I've typed a field name wrong, I've gotten a "Invalid field" error returned.

Thank you all for your help. It is what the boards are for.

SuperfellSuperfell
The problem is that Account and Contact are valid element names, its expecting you to pass in a nested account or contact object.
abhi_developerabhi_developer
Yes Dscer sometimes it's behaviour looks strange.. so watch out... keep on posting..
 
 
-Abhishek Singh