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
sf.dev.ax1103sf.dev.ax1103 

Zip file of all attachments

Hi All,

 

        I need to get the zip file of all attachments from case object where case status is closed.I tried using export wizard but no hope. Any help of how to extract zip file of all attachments.

 

Thanks

Best Answer chosen by Admin (Salesforce Developers) 
jeremyyjeremyy

I think I usually use the weekly export. It contains all attachments.

All Answers

jeremyyjeremyy

I think I usually use the weekly export. It contains all attachments.

This was selected as the best answer
sf.dev.ax1103sf.dev.ax1103

Thanks Jeremyy.Do you know any other way to extract attachments of just closed cases.

jeremyyjeremyy

It's possible to do via the api, so there may be a 3rd party tool that does it. The data loader can do it, but instead of creating a file for each attachment, you get a typical CSV, but the Body column contains the attachment's data, base64 encoded. You'd have to do the work to pull out that data, decode it, and do something with it.

jeremyyjeremyy

Just came across this python script I wrote a while back. I think I used it successfully, but don't really remember, so no guarantees.

 

It will take an attachment csv export from the data loader and do exactly what I explained before – for each record, decode the data and write it to a new file.

 

If you create a text file called extract_attachments.py, and you have a csv file called attachments.csv, execute the script like this:

 

python extract_attachments.py attachments.csv

extract_attachments.py

 

#! /usr/bin/env python

import sys
import csv
import base64
import io

csv.field_size_limit(1000000000)

if len(sys.argv) < 2:
	raise RuntimeException('File name should be passed as argument')
	
reader = csv.DictReader(open(sys.argv[1]), delimiter=',', quotechar='"')
for row in reader:
	f = io.open(row['NAME'], 'wb')
	f.write(base64.b64decode(row['BODY']))
	f.close()

 

sf.dev.ax1103sf.dev.ax1103

Thanks jeremyy. Can you please tell me how to run python script.

jeremyyjeremyy

To run the script, the command is:

 

python extract_attachments.py attachments.csv

 

You must have python 2.x installed.