0

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.

enter image description here

Thanks!

2

RecordType is a reference field. If you wanted to set the record type by name, you'd use that. However, since you already have the recordTypeId, you need to use the RecordTypeId field.

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?

No, that's a Record Type Id. You can tell because it starts with 012.

Is the RecordType property only settable once we've created the new Case record?

No, you can set it on insert, upsert, or update.

  • Boosh. @sfdcfox rocks! had this question up on SFDC's forums for 3 days with no answer. Post here and get one in 10 minutes. Thanks! – Jason Mar 24 '16 at 21:20

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.