I've been using the SOAP API to load different SObjects into an org. When I have a relationship, I can normally use an external ID as follows in order to set up relationships that exist between objects:

Opportunity opp = new Opportunity();
Account acc = new Account();

This creates a lookup from an opportunity to an account that I have the external id for.

however, for some reason I have run into a situation where the API is not offering me a setter method with a signature that I can use to perform the above.

I am being offered:

myCustomObj.setAnotherCustomObj__c(String AnotherCustomObj__c)


myCustomObj.setAnotherCustomObj__r(QueryResult AnotherCustomObj__c)

whereas, in order to use the external ids in the same way as I have been doing, I would need:

myCustomObj.setAnotherCustomObj__r(AnotherCustomObj__c anotherCO)

Does anyone know why I am not being offered this method signature?



As @superfell suggested, I'll post the field definition:

From Field List on FP_Order__c object

Order_Status__c lookup field definition

In addition, and along the same lines, I have run into an issue trying to set the Owner of the Order_Status__c object using an external ID. I was hoping to be able to do the following:

Order_Status__c orderStatus = new Order_Status__c();
User owner = new user();

yet I am not being offered a method on the Order_Status__c object whereby I can set the owner using a User object. Instead the methods I am being offered by the SOAP API are:

setOwner(String Owner__c)
setOwner(Name Owner)
setOwnerId(String OwnerId)

In order to use these method, I would first have to select information (e.g. the owner id) from the database, whereas I would ideally like to set the Owner using an external id which I would already have.

  • Do you have any ext. id / unique field on the lookup target (AnotherCustomObj__c)? If you do - maybe you've marked it as ext. id it after you downloaded the WSDL - can you obtain fresh one and regenerate your classes?
    – eyescream
    Jan 29 '13 at 12:48
  • Definitely have a live ext id that has been included in the WSDL as I can use it in a lookup from another object.
    – Joe
    Jan 29 '13 at 12:52
  • Have you tried constructing a QueryResult, placing a object instance in it and setting the field that represents the external reference? This is broadly how it works when using the Partner API, salesforce.stackexchange.com/questions/17660/… Nov 28 '13 at 15:05

Your AnotherCustomObj__r relationship is a parent to child relationship, not a lookup, in these case, the child object has a lookup to the parent, the parent doesn't have a direct lookup to the child (as there can be many child rows)

  • it doesn't look like that's the case, the question uses the opportunity -> account relationship as an example which implies a lookup relationship not a parent to child Jan 29 '13 at 16:37
  • yes, oppty -> account is perfectly valid, the signature of the relationship in the question indicates though that this is a parent-child relationship.
    – superfell
    Jan 29 '13 at 17:03
  • doesn't the __r just imply a relationship which can be either? i.e. opportunity.parent_object__r = new Parent_Object__c() or (select (select Opportunities__r) from Parent_Object__c) Jan 30 '13 at 1:12
  • __r implies relationship of either direction, but because the parameter is a queryresult (a collection of records), rather than a single record,it can be inferred that this is a parent-child relationship.
    – superfell
    Jan 30 '13 at 3:09
  • Thanks but it is definitely a child to parent (lookup) relationship. I can easily check using workbench and the relationship is there.
    – Joe
    Jan 30 '13 at 15:30

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.