Java to Salesforce Connection

Step 1: Generate or Obtain the Web Service WSDL
To generate the WSDL file for your organization:
  • Log in to your Enterprise, Unlimited, or Developer Edition Salesforce account. You must log in as an administrator or as a user who has the “Modify All Data” permission.
  • Click Your Name > Setup > Develop > API to display the WSDL download page.


  • Click Generate Enterprise WSDL.
  • Salesforce prompts you to select the version of each installed package to include in the generated WSDL.
  • Click Generate.
  • In the right-click menu, Internet Explorer users can choose Save Target As, while Mozilla Firefox users can choose Save Link As.
 
Step 2: Download wsc.jar 
Download wsc.jar from http://code.google.com/p/sfdc-wsc/downloads/list 

Step 3: Move all the required files into bin folder 
Move wsc.jar and enterprise.wsdl.xml into C:\Program Files\Java\jdk1.6.0_12\bin. 

Step 4: Generate enterprise.jar

Syntax: 
java –classpath pathToJAR/wsc-20.jar com.sforce.ws.tools.wsdlc pathToWsdl/WsdlFilename pathToJar/JarFilename 

Sample: 
Java –classpath wsc.jar com.sforce.ws.tools.wsdlc enterprise.wsdl.xml enterprise.jar
This command will generate enterprise.jar in the same directory C:\Program Files\Java\jdk1.6.0_12\bin. After these files are compiled, they can be included in your Java programs for use in creating client applications.

Below is the successful execution of the command.


Note: Never copy the sample syntax and paste it in your Command Prompt.

Step 5: Create a Project in Eclipse
1. Create a Project ‘API’ using Eclipse 
 


2. Click Finish.
3. Right click the API Project and create new Package wsc.


4. Click Finish.
6. Add all the required Jars (wsc.jar, enterprise.jar)
7. To add the Jars, Right Click Project API, Select Build Path and then select Configure Build Path.


 
Browse and select the jars to include.

8. Add enterprise.wsdl.xml file.
To add enterprise.wsdl.xml file, copy the enterprise.wsdl.xml file and Right click API Project and Paste it.



9. Check proxy settings in Eclipse


Proxy Settings(Optional):

11 comments:

  1. Hi,

    This is a nice tutorial, and I followed the same approach and I could not generate enterprise.rar file


    C:\Program Files\Java\jdk1.8.0\bin>java -classpath wsc-23.jar com.sforce.ws.tool
    s.wsdlc enterprise.wsdl.xml enterprise.jar
    [WSC23][wsdlc.run:348]Created temp dir: C:\Users\AJAYKU~1\AppData\Local\Temp\wsd
    lc-temp-4059106662678269573-dir
    [WSC23][wsdlc.:110]Generating Java files from schema ...
    [WSC23][wsdlc.:110]Generated 473 java files.
    [WSC23][wsdlc.compileTypes:298]Compiling to target default...
    [WSC23][wsdlc.compileTypes:298]Compiled 476 java files.
    [WSC23][wsdlc.:120]Generating jar file ... enterprise.jar
    Exception in thread "main" java.io.FileNotFoundException: enterprise.jar (Access
    is denied)
    at java.io.FileOutputStream.open(Native Method)
    at java.io.FileOutputStream.(FileOutputStream.java:206)
    at java.io.FileOutputStream.(FileOutputStream.java:95)
    at com.sforce.ws.tools.wsdlc.generateJarFile(wsdlc.java:212)
    at com.sforce.ws.tools.wsdlc.(wsdlc.java:120)
    at com.sforce.ws.tools.wsdlc.run(wsdlc.java:348)
    at com.sforce.ws.tools.wsdlc.main(wsdlc.java:339)

    This is the error I am getting it. Any suggestions please?

    Thanks,
    Ajay

    ReplyDelete
    Replies
    1. The problem is you don't have rights to create a file inside the bin folder.
      Kindly check it.

      Cheers!!!

      Delete
    2. hi Magulan,

      I am getting this error please solve it.......

      C:\Program Files\Java\jdk1.6.0_11\bin>java -classpath wsc-23.jar com.sforce.ws.t
      ools.wsdlc enterprise.wsdl.xml enterprise.jar
      [WSC23][wsdlc.run:348]Created temp dir: C:\Users\Ravi\AppData\Local\Temp\wsdlc-t
      emp-4455986279418520348-dir
      [WSC23][wsdlc.:110]Generating Java files from schema ...
      [WSC23][wsdlc.:110]Generated 577 java files.
      [WSC23][wsdlc.compileTypes:298]Compiling to target default...


      The system is out of resources.
      Consult the following stack trace for details.
      java.lang.OutOfMemoryError: Java heap space
      at com.sun.tools.javac.util.Position$LineMapImpl.build(Position.java:139
      )
      at com.sun.tools.javac.util.Position.makeLineMap(Position.java:63)
      at com.sun.tools.javac.parser.Scanner.getLineMap(Scanner.java:1105)
      at com.sun.tools.javac.main.JavaCompiler.parse(JavaCompiler.java:512)
      at com.sun.tools.javac.main.JavaCompiler.parse(JavaCompiler.java:550)
      at com.sun.tools.javac.main.JavaCompiler.parseFiles(JavaCompiler.java:80
      1)
      at com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:727)
      at com.sun.tools.javac.main.Main.compile(Main.java:353)
      at com.sun.tools.javac.api.JavacTaskImpl.call(JavacTaskImpl.java:115)
      at com.sforce.ws.tools.wsdlc$Compiler.compile(wsdlc.java:491)
      at com.sforce.ws.tools.wsdlc.compileTypes(wsdlc.java:298)
      at com.sforce.ws.tools.wsdlc.(wsdlc.java:119)
      at com.sforce.ws.tools.wsdlc.run(wsdlc.java:348)
      at com.sforce.ws.tools.wsdlc.main(wsdlc.java:339)
      [WSC23][wsdlc.compileTypes:298]Compiled 580 java files.
      [WSC23][wsdlc.:120]Generating jar file ... enterprise.jar
      Exception in thread "main" java.io.FileNotFoundException: enterprise.jar (Access
      is denied)
      at java.io.FileOutputStream.open(Native Method)
      at java.io.FileOutputStream.(FileOutputStream.java:179)
      at java.io.FileOutputStream.(FileOutputStream.java:70)
      at com.sforce.ws.tools.wsdlc.generateJarFile(wsdlc.java:212)
      at com.sforce.ws.tools.wsdlc.(wsdlc.java:120)
      at com.sforce.ws.tools.wsdlc.run(wsdlc.java:348)
      at com.sforce.ws.tools.wsdlc.main(wsdlc.java:339)

      please I have tried in many ways but I am getting out of this message....
      solve it please...
      Thanks in advance....

      Delete
    3. Hi Ajay Kumar,
      You don't have permission to create any file into C-Drive so, just create "Enterprise.jar" in any other directory and the copy it into 'jdk->Bin'.

      Example-

      C:\Program Files\Java\jdk1.6.0_45\bin>java -classpath wsc-23.jar com.sforce.ws.tools.wsdlc enterprise.wsdl "D:\enterprise.jar"

      Delete
  2. sir i also have the same problem as Ajay mention above plzzzz....help

    ReplyDelete
  3. Hi ,

    I want to use bulk inserting records fron csv file (70,000 reocrds approx.) from external app(java). I have checked you examples from calling from java to salsforce. But how to call this java class from salesforce with csv file data which the user uploading in salesforce?

    Any ideas here will help me a lot.

    Regards,
    Kumaresan M

    ReplyDelete
  4. Am i need to use REST API in salesforce with csv file data in body of the call. If yes, then for example in my java rest class, if i call the class (which will insert 70k records) will it be same transaction. (whether Time out limits are there or not) ? What is the way around here ?

    Regards,
    Kumaresan M

    ReplyDelete
  5. I am facing issues with sales force heap size limit and other limits while processing bulk records from csv. Thats why we are planning to use java here ? Is it correct approach?

    Regards,
    Kumaresan M

    ReplyDelete
  6. Hi @AJESH I also faced the same error so,for this instead of "enterprise.wsdl.xml" use "enterprise.wsdl",it will work.

    ReplyDelete
  7. This information helped me allot. Very nice work.Really thanks for sharing this great article.

    ReplyDelete