Sunday, 26 June 2016

Storing the attachments in Local Folder from through JAVA using enterprise WSDL


We have a requirement to store attachmentsv in a local folder from that we have to download Enterprise.wsdl and convert it into Enterprise.jar by using wsc-23.jar then add them to your java project . After this process you just need to create the following class.

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.soap.enterprise.sobject.Doctor__c;
import java.util.ArrayList;
import java.util.List;

public class ExportDocstoFFolder {

public static void main(String[] args) throws NumberFormatException, IOException, URISyntaxException {

  //Create a new connectionconfig to your Salesforce Org
   ConnectorConfig sfconfig = new ConnectorConfig();
   //Use your salesforce username = email
   //Use your saleforce password with your security token look like:
   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");   
       boolean done = false;
        for (int k = 0; k < describeGlobalResult.getRecords().length; k++)
           Attachment a = (Attachment)describeGlobalResult.getRecords()[k];
           File path = new File("F://SFDCAttachments//Balaji");
           String mySubFolder=a.getId();          
           File newDir = new File(path + File.separator);        
           boolean success = newDir.mkdirs();          
           FileOutputStream fos = new FileOutputStream(newDir + File.separator+ a.getName());
        if (describeGlobalResult.isDone()) {
               done = true;
            } else {
            describeGlobalResult = partnercon.queryMore(describeGlobalResult.getQueryLocator());
   } catch (ConnectionException e) {      

out put :
After running java class:

"F" folder which is recieved attachements:

To generate Jar files for Enterprise.wsdl

1 comment:

Create Dynamic Picklists for Your Custom Components (design:component)

Hi, We can expose a component property as a picklist when the component is configured in the Lightning App Builder. The picklist’s value...