I am using the Java API and trying to create an Attachment
with a reference to the Parent external Id
field. The setParent()
method takes a Name
object as the parameter.
For what I read, the Name
object is to allow references to another object that can be of different types (Account
, Campaign
, Opportunity
, ...), but I have no idea on how to use it.
In any other object that has a relationship to, let's say, Account
(account__c
) I can setAccount__c(theAccountId)
or setAccount__r(accountWithOnlyExternalIdField)
.
Any info on how to use this Name
object?
Edit to add example with Task object in case it was not clear:
//Create Task related to Account by Id
Task t = new Task();
t.setAccountId("001O000000SQ1xD");
//we can insert task and it will link to the account with id 001O000000SQ1xD
//Create Task related to Account by externalId field
Task t = new Task();
Account a = new Account();
a.setMyCustomExternalId__c("12345")
t.setAccount(a);
//we can insert task and it will link to the account which has MyCustomExternalId__c 12345
Edit 2: I begin to suspect that this may not be possible. The Name
object reference says:
This object is used to retrieve information from related records where the related record may be from more than one object type (a polymorphic foreign key). For example, the owner of a case can be either a user or a group (queue). This object allows retrieval of the owner name, whether the owner is a user or a group (queue). You can use a describe call to access the information about parents for an object, or you can use the who, what, or owner fields (depending on the object) in SOQL queries. This object cannot be directly accessed. Source: Name object referece
If this is accurate and the Attachment.setParent()
can not be used despite the fact that it is exposed, then maybe the question title should be rephrased to something like "How to set a polymorphic foreign key by its external id instead of its id".