Scenario :
Suppose we have a SOAP web service in one Salesforce ORG, as mentioned in my below post (SOAP Web Service Example in Apex.). Now in this service there is a web method named as createEmployeeRecord(), containing 2 parameters,
Employee name in String format.
Employee roll number in Integer format.
This web method is responsible for Inserting employee records based on parameters passed.
Now, our aim is to call this web method from a JAVA application.
Solution :
Below are the detail steps to solve the above scenario,
To do this, we need 3 external JAR files,
a> force-wsc-29.0.0.jar (Version can be change, for this example I used V-29.0.0)
b> Jar file generated form Enterprise WSDL,
c> Jar file generated for your web-service WSDL.
Once the above Jars are ready, then crate a JAVA Project and add these jar files to in project library. Finally copy paste the below class code to call the web service method named as createEmployeeRecord().
JAVA Code Example :
NOTE:
Check my next post to know how to create a jar file from WSDL
Suppose we have a SOAP web service in one Salesforce ORG, as mentioned in my below post (SOAP Web Service Example in Apex.). Now in this service there is a web method named as createEmployeeRecord(), containing 2 parameters,
Employee name in String format.
Employee roll number in Integer format.
This web method is responsible for Inserting employee records based on parameters passed.
Now, our aim is to call this web method from a JAVA application.
Solution :
Below are the detail steps to solve the above scenario,
To do this, we need 3 external JAR files,
a> force-wsc-29.0.0.jar (Version can be change, for this example I used V-29.0.0)
b> Jar file generated form Enterprise WSDL,
c> Jar file generated for your web-service WSDL.
Once the above Jars are ready, then crate a JAVA Project and add these jar files to in project library. Finally copy paste the below class code to call the web service method named as createEmployeeRecord().
JAVA Code Example :
import com.sforce.soap.enterprise.Connector; import com.sforce.soap.enterprise.EnterpriseConnection; import com.sforce.ws.ConnectionException; import com.sforce.ws.ConnectorConfig; public class MainClass { static final String USERNAME = "user name of the ORG of webservice"; static final String PASSWORD = "password"; static EnterpriseConnection connection; public static void main(String[] args) { ConnectorConfig config = new ConnectorConfig(); config.setUsername(USERNAME); config.setPassword(PASSWORD); try { System.setProperty("https.protocols", "TLSv1.1,TLSv1.2"); connection = Connector.newConnection(config); com.sforce.soap.MyWebService.SoapConnection soap = com.sforce.soap.MyWebService.Connector.newConnection("", ""); soap.setSessionHeader(config.getSessionId()); System.out.println(soap.createEmployeeRecord("Jhon", 103)); } catch (ConnectionException e1) { e1.printStackTrace(); } } }
NOTE:
Check my next post to know how to create a jar file from WSDL