When using the SOAP API, we're getting an error when trying to set the RecordType value on the Case object:
The external foreign key reference does not reference a valid entity: RecordType; Error Code: INVALID_FIELD
This code seems to work fine:
// Create sObject & Fields...
var xml = new XmlDocument();
var xmlElements = new XmlElement[4];
xmlElements[0] = xml.CreateElement("ContactId");
xmlElements[0].InnerText = contactId;
xmlElements[1] = xml.CreateElement("Subject");
xmlElements[1].InnerText = reportType;
xmlElements[2] = xml.CreateElement("Description");
xmlElements[2].InnerText = description;
xmlElements[3] = xml.CreateElement("Origin");
xmlElements[3].InnerText = vendorOriginId;
var record = new sObject();
record.type = "Case";
record.Any = xmlElements;
// Add sObject to Array...
var recordList = new sObject[1];
recordList[0] = record;
// Execute...
var results = sforceService.create(recordList);
This code causes the failure (and above error message to be returned):
// Create sObject & Fields...
var xml = new XmlDocument();
var xmlElements = new XmlElement[5];
xmlElements[0] = xml.CreateElement("ContactId");
xmlElements[0].InnerText = contactId;
xmlElements[1] = xml.CreateElement("Subject");
xmlElements[1].InnerText = reportType;
xmlElements[2] = xml.CreateElement("Description");
xmlElements[2].InnerText = description;
xmlElements[3] = xml.CreateElement("Origin");
xmlElements[3].InnerText = vendorOriginId;
xmlElements[4] = xml.CreateElement("RecordType");
xmlElements[4].InnerText = recordTypeId;
var record = new sObject();
record.type = "Case";
record.Any = xmlElements;
// Add sObject to Array...
var recordList = new sObject[1];
recordList[0] = record;
// Execute...
var results = sforceService.create(recordList);
If we pull the XML node out for RecordType, the create() method works fine, so we've isolated this node to be the culprit. We got the Reference ID from the dropdown list provided in the SFDC GUI, so we're fairly certain that we're correct here too. Are we missing something? Is the RecordType property only settable once we've created the new Case record? Any help would be much appreciated.
Thanks!