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
tony2009tony2009 

upsert attachment with relationships from command line

Hi Guys.

 

I am using the data loader command line to copy data from external system to salesforce.

 

I have two objects in salesforce, as well as external system, media and attachement.  media is parent, attachment is child.

 

In the attachment mapping file, the relationship item is 

 

Media__c\:Parent\:ExternalID__c 

 

so that the attachment could  be inserted with the relationship of media. 

 

But I got error message 

 

mapping is invalid: MediaId => Media__c:Parent:Ext
ernalID__c

 

I also tried Parent\:ExternalID__c as well, got similar error message. 

 

Note: I have uploaded the Media data with extenal Id successfully. 

 

How should I specify the mappings?

 

Thanks in advance.

 

 

 

Best Answer chosen by Admin (Salesforce Developers) 
Navatar_DbSupNavatar_DbSup

Hi,

 

There is no external ID field defined on Attachment object. The ID field will be used for matching.

So there is no way to upsert attachment.

 

Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved. 

All Answers

Navatar_DbSupNavatar_DbSup

Hi,

 

There is no external ID field defined on Attachment object. The ID field will be used for matching.

So there is no way to upsert attachment.

 

Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved. 

This was selected as the best answer
Haris Osmanagic, B&HHaris Osmanagic, B&H
@Navatar_DbSup: It's been 3 years since this question was answered, but I'm having some similar problem with attachments. Anyway... Why do you say there's no way to upsert attachments? When you go to docs for upsert() (https://www.salesforce.com/developer/docs/api/Content/sforce_api_calls_upsert.htm), it says: This call is available for objects if the object has an external ID field or a field with the idLookup field property. Attachment's ID field has the idLookup property. Reason #2: When you go to docs for Attachment (https://www.salesforce.com/developer/docs/api/Content/sforce_api_objects_attachment.htm), you can see upsert() in the Supported calls section.
Wim VelzeboerWim Velzeboer

You can use upsert on the Attachment object, but only on the Salesforce ID field of the attachment. You cannot use upsert with an own (External ID) field, because you cannot create custom fields on the attachment object.

To bypass this, you could write a trigger on the Attachment object, to check if the record already exists. If it does you can throw an error, and handle that error on the uploading side of your logic.