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

Using partner WSDL to upsert foreign key relationship on custom object

Hi, I am able to upsert a contact record referencing the external field of its account relationship. But if I try to do that with a custom table I get the following error:

"Unexpected element {}type during simple type deserialization"

Does anyone have any experience or insight into this issue? Here's the code fragment in question:

    ArrayList elements = new ArrayList();

    elements.add(new MessageElement(new QName("SPS_Account_ID__c"), id));

    // Foreign key relationship to the Account object
    MessageElement client_me = new MessageElement(new QName("Account__c"));
    client_me.addChild(new MessageElement(new QName("type"), "Account"));
    client_me.addChild(new MessageElement(new QName("Client_ID__c"),  accountID));

    SObject[] sObjects = new SObject[1];
    sObjects[0] = new SObject();
    sObjects[0].set_any((MessageElement[]) elements.toArray(new MessageElement[elements.size()]));

Message Edited by steven.warren on 04-08-2008 04:45 PM
You need to use the relationship name, not the field name, you set your child sobject structure on the account__c field, but that's an Id field, it should be set on the account relationship, account__r
Worked great! Thanks for the quick response. :smileyhappy:

Hello Steven,


Can you please give me the code snippet to upsert foreign key relationship on an object using Partner WSDL

(may be using Account and Contact)?



Ramana Maddikunta 




Can you point me to a c# solution for partner wsdl that uses external ID of parent to insert child object?