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
chris04chris04 

MALFORMED_ID creating custom SObject instance with a FieldType.Lookup using Partner API

Hi all,

I've successfully used the Metadata API to create two custom objects, one a parent, and one a child with a reference field of type Lookup pointing at the parent.  I am able using the Salesforce UI to populate that child's reference field to the parent, however I am getting a "MALFORMED_ID", "id value of incorrect type" error when doing it using the Partner API.  Is there somethign special I need to do when creating the reference field's MessageElement object?

Thanks,
Chris


Message Edited by chris04 on 07-10-2008 12:20 PM

Message Edited by chris04 on 07-10-2008 12:21 PM
SuperfellSuperfell
What Id value are you setting it to?
chris04chris04
I am setting the field TestObject__c I created on the child with FieldType.Lookup to a valid TestObject__C value of "123456".  I've tried setting it to this value through the UI and it works.  The toString() method on the child's reference MessageElement I am creating looks like this

<TestObject__c xsi:type="xsd:string" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">123456</TestObject__c>

If I describe the TestObject__c (parent), and Part__c (child), they look like the following:

----------- Describe SObject -----------
Name: TestObject__c
Label: TestObject
Plural Label: TestObjects
Number of fields: 16
Field {id}: Record ID
Field {reference}: Owner ID
Field {boolean}: Deleted
Field {string}: TestObject Name
Field {datetime}: Created Date
Field {reference}: Created By ID
Field {datetime}: Last Modified Date
Field {reference}: Last Modified By ID
Field {datetime}: System Modstamp
Field {date}: Last Activity Date
Field {string}: ObjectID
Field {string}: EventID
Field {string}: ACTION
Field {string}: FromUserID
Field {datetime}: Timestamp
Field {string}: FromUser

----------- Describe SObject -----------
Name: Part__c
Label: Part
Plural Label: Parts
Number of fields: 14
Field {id}: Record ID
Field {reference}: Owner ID
Field {boolean}: Deleted
Field {string}: Part Name
Field {datetime}: Created Date
Field {reference}: Created By ID
Field {datetime}: Last Modified Date
Field {reference}: Last Modified By ID
Field {datetime}: System Modstamp
Field {date}: Last Activity Date
Field {string}: quanitity
Field {reference}: TestObject
Field {datetime}: Timestamp
Field {string}: ObjectID

Finally, if I debug and examine the Field object during the describe call for that field, the soapType = "tns:ID" and the type = "reference".

I think I just need to understand how I can indicate on the MessageElement object the appropriate type for a field that is a reference.

Chris


Message Edited by chris04 on 07-10-2008 01:02 PM
SuperfellSuperfell
123456 is not a valid Id, you need the Id value of the record you want to reference, not its name or autonumber value.
chris04chris04
Ok, so let me make sure I understand then. 

Upserting allows use of an ExternalID, i.e. 123456, etc.

However in order to reference a Parent object from a Child object, you must use the Parent's actual Salesforce ID and not an ExternalID or Name.

I tried this and it appears to work, thanks very much for the help. 

I could see it being useful to be able to be able to set the reference to the Parent using its ExternalID if it has one.  As it stands now, you need to know the Parent's ID or query the API to get the Parent's ID in order to construct a Child that references the Parent, even though I know the ExternalID of the Parent at the time I am attemping to create the Child.

Thanks again for the response,
Chris


Message Edited by chris04 on 07-10-2008 02:09 PM
SuperfellSuperfell
Right. You can use externalIds using upsert, you need to embed the value into a nested element. (the easiest way to work it out is to use the enterprise WSDL, see the XML is generates, then do the same in the partner API).

e.g. instead of
<accountId>001...</accountId>
you'd do
<account>
<type>account</type>
<myExtId__C>12345</myExtId>
</account>

where accountId is the name of hte lookup field, and account is the name of the relationship.

Message Edited by SimonF on 07-10-2008 02:38 PM