I wrote a class the exports Salesforce Attachements to be exported to your local Machine. I put the exported attachement files in a dropbox folder which is automatically the shared with others in the organization.
Note: make sure the export directory is shared on Dropbox.
package com.thys.michels.sfdc.doc;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.net.URISyntaxException;
import com.sforce.soap.enterprise.Connector;
import com.sforce.soap.enterprise.EnterpriseConnection;
import com.sforce.soap.enterprise.QueryResult;
import com.sforce.soap.enterprise.sobject.Attachment;
import com.sforce.ws.ConnectionException;
import com.sforce.ws.ConnectorConfig;
public class SFDCDoc {
/**
* @param args
* @throws NumberFormatException
* @throws IOException
* @throws URISyntaxException
* @throws DOMException
*/
public static void main(String[] args) throws NumberFormatException, IOException, URISyntaxException {
// TODO Auto-generated method stub
//Create a new connectionconfig to your Salesforce Org
ConnectorConfig sfconfig = new ConnectorConfig();
//Use your salesforce username = email
sfconfig.setUsername("yourusername");
//Use your saleforce password with your security token look like: passwordjeIzBAQKkR6FBW8bw5HbVkkkk
sfconfig.setPassword("passwordwithsecuritytoken");
EnterpriseConnection partnercon = null;
try {
// create a salesforce connection object with the credentials supplied in your connectionconfig
partnercon = Connector.newConnection(sfconfig);
QueryResult describeGlobalResult = partnercon.query("select Id, Name, Body from Attachment where ContentType='application/pdf'");
System.out.println(describeGlobalResult.getRecords().length);
boolean done = false;
while(!done)
{
for (int k = 0; k < describeGlobalResult.getRecords().length; k++)
{
Attachment a = (Attachment)describeGlobalResult.getRecords()[k];
File path = new File("//Users//tmichels//Dropbox//SFDCAttachments");
String mySubFolder = a.getId();
File newDir = new File(path + File.separator + mySubFolder);
System.out.println(newDir);
boolean success = newDir.mkdirs();
FileOutputStream fos = new FileOutputStream(newDir + File.separator+ a.getName());
fos.write(a.getBody());
fos.close();
}
if (describeGlobalResult.isDone()) {
done = true;
} else {
describeGlobalResult = partnercon.queryMore(describeGlobalResult.getQueryLocator());
}
}
} catch (ConnectionException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}