+ Start a Discussion
Alex Wong 4Alex Wong 4 

How to export attachment?

Is there any method to export the attacments of custom object?
Best Answer chosen by Alex Wong 4
Ishwar ShindeIshwar Shinde
Hi,

You can use "Data Export" functionality of salesforce to get object data allong with attachmnets. 

Please refre below link for more details - 

https://www.shellblack.com/administration/data-export/

Hope it is helpful.

Thanks,
Ishwar Shinde

All Answers

Pruthvi KankunthalaPruthvi Kankunthala
@Alex :
Programmatically
 The best way to get the actual attachment data out of Salesforce is to query the Attachment object for the Attachment Ids and then use the retrieve() API call to get the Body data. I have done this before for integrations and it is very fast.

You can try this code :
select Id, Custom_Field__c, 
(SELECT Id, Name FROM Attachments), 
(SELECT Id, Title FROM Notes) 
from Custom_ObjectAPIName__c

Using Data Loader :

Check this article . It contains step by step procedure to export attachments .
http://dataloader.io/dealing-attachments
Alex Wong 4Alex Wong 4
Thanks for you help! But I don't quite understand where can I place the above code?
Pruthvi KankunthalaPruthvi Kankunthala
@Alex : You have to paste the above code in the Developer Consoler !!!
Ishwar ShindeIshwar Shinde
Hi,

You can use "Data Export" functionality of salesforce to get object data allong with attachmnets. 

Please refre below link for more details - 

https://www.shellblack.com/administration/data-export/

Hope it is helpful.

Thanks,
Ishwar Shinde
This was selected as the best answer
Alex Wong 4Alex Wong 4
@Pruthvi Kankunthala How can I view the body of the attachments? When I insert:
select Id, Name, 
(SELECT Id, Name, Body FROM Attachments)
from Artist__c
It shows back "Binary fields cannot be selected in join queries".
Alex Wong 4Alex Wong 4
@Ishwar Shinde How can I change the name and the type of attachment? 
User-added image
It is hard for me to guess which software should I use for opening the file, since some of them are pdf or jpg. And I also the a name for identifying which record belongs to. Thank you. 
Ishwar ShindeIshwar Shinde
Hi Alex,

Please try below steps to rename the attachments  - 

https://help.salesforce.com/apex/HTViewSolution?id=000007269&language=en_US

Hope it will help.

Thanks,
Ishwar Shinde
Alex Wong 4Alex Wong 4
@Ishwar Shinde It works well. But I want to ask one more question. How can I solve the problem of repeating file name? It seems that the file with repaeting name cannot be fixed by this approach. Is there any method to change the name inside the database before exporting it out? Thanks.
Ishwar ShindeIshwar Shinde
Hi Alex,

Here are few options which I can think of- 
1. Write the apex code/batch which will check the duplicate attachment name and rename it uniquely. 
Or
2. Export the attachmnet Id and Name using data loader. Find duplicates in excel, rename it and then again update the name in salesforce using data loader.
Or
3. Add validation on Name field to make it unique by code.It will avoid creation of attachmnet with duplicate names.
Or
4. In excel which you have exported, check for duplicate names and make it uniquie locally before renaming file name. 

Hope anything from above will work for you.
Alex Wong 4Alex Wong 4
@Ishwar Shinde Thanks for your help! Here is my situation now: My custom object is actually a form for public to fill in their information. In the form, there are 3 question for them to upload the attachment. One of the question can allow them to insert 1-3 attachment(s), and the other two question can only insert 1 attachment. Is there any way to rename the attachment, so that I can know that which attachment belongs to which question? Actually, it is not a must. The backup plan is to just simply ask the uploader to rename according to format before they upload. 
Really appreciate you work! Thank you.
Ishwar ShindeIshwar Shinde
Hi Alex,

On insert of attachment, you can write trigger and rename the attachment (considering you know how and what name you need to specify for attachment).

Please mark this as best ans if this helps!!
Alex Wong 4Alex Wong 4
@Ishwar Shinde Sorry, I am really quite new to Salesforce. I want to ask that after writing a trigger, where can I call it? And since attachment only have one field in a record of custom object, how can I identify them in a trigger? I can identify them in my aoex code since I use variable in there. Can this variable also use in triggers? Also, can triggers just add the name of record in front the attachment? 
Example:
There should be 3 type of attachment, A, B and C. For example, team A submit the form. I want the attachments to be TeamA_A.
Can triggers perform this? Thanks for your help!
Sumit Kumar Singh 9Sumit Kumar Singh 9
You can try this tool, if you want to extract Salesforce files, Documents and attachmkents in its original format.
https://www.sfdcfileexporter.com/sffxhome
Gulshan Middha 1 6Gulshan Middha 1 6
This tool can be used as well: http://www.sfdctimes.com/export_sfdc_files/
Fjolla DafinaFjolla Dafina
If you don`t want to code or you don`t have enough time for it, take a look at - https://skyvia.com/
Sonam MeshramSonam Meshram
Hi Alex,
You can try this tool : https://sforce.co/34thF8U
where you can download almost any Attachment or File under one or multiple records all at once and also support download of Static Resource and Documents too.


Thank,
Sonam
S3-LinkS3-Link
S3- Link is FREE App for Salesforce - Amazon S3 Connector. Its also available on Appexchange. 
 
  1.     Attach file related to any Salesforce object on Amazon S3.
  2.     Move existing Salesforce files and attachments in Amazon S3
  3.     Multiple file uplaod.
  4.     No file size limit for upload.
  5.     File access control capabiliy.
  6.     Track file downloads by users.
  7.     File exlorer capability.
https://appexchange.salesforce.com/listingDetail?listingId=a0N3000000CW1OXEA1

Here is our email address. Let us know if you have any query.
support@neiloncloud.com

Thanks.