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
Jason ChristmanJason Christman 

update lookup based on relationship external_Id using Partner WSDL and C#

Looking for a clean way to update a record and set its relationship id based on the relationships external_Id field. 
 
sObject sobject = new sObject();
sobject.type = "CustomObject__c";

XmlDocument doc = new XmlDocument();
List<XmlElement> objElements = new List<XmlElement>();

XmlElement nElement = doc.CreateElement("Name");
nElement.InnerText = "TestName";
objElements.add(nElement);

//
//  This does not work but provides example of what I want to do.
// 
XmlElement rElement = doc.CreateElement("Account__r.tsExternal_Id__c");
rElement.InnerText = "External_Id";
objElements.add(rElement);


sobject.Any = objElements.ToArray();
DataLoader does the relationship lookup based on external Ids, I am hoping there is away that does not require for another query to get the actual Id.
 
Daniel BallingerDaniel Ballinger
I think the solution to Change account owner with external id on user - partner wsdl (C#) (http://salesforce.stackexchange.com/a/61046/102) covers what you want to do. Note in the answer how the associated record is created as an inner element and then the external field as a child of that.