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

Specifying External ID of related (lookup) object in Master object's Upsert call



We are Upserting a custom object A using API calls from .Net code. In the Upsert call, we have been specifying External ID of the custom object A. Now, A has a lookup relationship with custom object B. We are thinking if A can be upserted and linked (with B) in one API call. For example, when we upsert using Data Loader, there is a way to specify lookup relationship in .sdl file.





We are searching for a similar way of doing this in our .Net code to save number of API calls to link B to A. In the Apex API guide, there are examples of Upserting objects with its own external IDs but not with related (lookup, Parent objects) objects by specifying their External IDs. Please share if anyone is having any idea about it.




Is the example in the link going to work for custom objects too?




Hey Simon,


Thanks for help!


In this example, the case record is being inserted (not upserted) and Account is also created on the fly. Whereas in our case the custom object B's record already exist in salesforce and we are Upserting A's records and want to link B's records in the same Upsert call.


The way we want to implement is the linking of Custom object B can be done in Upsert call to A itself. Rather than having statements to create new B records and assign external IDs to its field; we would like to sepcify the external ID in Upsert call itself.


As of now we are doing Upsert like


Upsert(<A's external ID field>, <list of A's records>);


Now, if we can pass the B's external ID field value too in this call, the linking should be achieved (Lookup value on object A should be populated with B's record).


Please let me know if I am not making myself clearer.




In the example i posted the case is created (but it could equally well be updated, or upserted, it doesn't matter), and the account is not created, its just a reference to an existing account, based on that externalId field on account's value. as far as i can tell, this is what you're looking for.


Thanks a lot Simon !!


We got this resolved.