0

When creating a new record using the partner wsdl SOAP API how do I add the parent id to the generic sObject.

We have a parent record of Account__c and child records of Store_Visit__c

My attempted code is below:

sObject parAccount = new sObject();
System.Xml.XmlElement[] objAccountFields = new System.Xml.XmlElement[1];
System.Xml.XmlDocument docAcc = new System.Xml.XmlDocument();
objAccountFields[0] = docAcc.CreateElement("ExternalID__c");
objAccountFields[0].InnerText = "SF-0113120";

parAccount.Id = "SF-0113120";
parAccount.type = "Account__c";
parAccount.Any = objAccountFields;
            
sObject newvisit = new sObject();
System.Xml.XmlElement[] objFields = new System.Xml.XmlElement[6];
// Create the contact's fields
System.Xml.XmlDocument doc = new System.Xml.XmlDocument();
objFields[0] = doc.CreateElement("API_Uploaded__c");
objFields[0].InnerText = "true";
objFields[1] = doc.CreateElement("Number_of_People_Trained__c");
objFields[1].InnerText = "3";
objFields[2] = doc.CreateElement("Training_Executed__c");
objFields[2].InnerText = "true";
objFields[3] = doc.CreateElement("Visit_Date__c");
objFields[3].InnerText = "2022-06-27";
objFields[4] = doc.CreateElement("Visit_Notes__c");
objFields[4].InnerText = "TEST DATA";
objFields[5] = doc.CreateElement("Account__c");
objFields[5].?? = parAccount;

newvisit.type = "Store_Visit__c";
newvisit.Any = objFields;

How do I pass the sObject for Account__c into the Any fields of the Store_Visit_c sObject??

I previously tried passing the ID like this:

objFields[5] = doc.CreateElement("Account__c");
objFields[5].InnerText = "SF-0113120";

But get the following error

Error code is: MALFORMED_ID Error message: Account: id value of incorrect type: SF-0113120

As I believe Account__c is a Reference type field

1 Answer 1

0

It turns out that I was using the auto number for the ID when it should have been an actual ID number

using the following worked fine.

objFields[5] = doc.CreateElement("Account__c");
objFields[5].InnerText = "0011j00001Z05bXAAR";

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .