Creating custom Apex SOAP based on Web Services in Salesforce.com and accessing from Java Application

What Is SOAP API?

SOAP API is used to create, retrieve, update or delete records, such as accounts, leads, and custom objects. It supports data in the form of XML. Requires WSDL files for the integration.

What are the Steps?

  • Navigate to setup -> Develop -> Apex Classes and create new class by clicking new button.
  • Write a class with “global” access modifier with methods.
  • Methods must be start with “Webservice” keyword.

1

  • Save the above class. After saving the class you will see the button “Generate WSDL”. Click on that to get WSDL for web service. Save the WSDL file named as “SuryaDhruvsoftWebservice.wsdl”
  • Now we will see how to access this WSDL file using JAVA

What are the steps for Java

  • Create a Dynamic web project named as “ApexSOApCustomWS” in eclipse.
  • Generate a Enterprise/Partner WSDL from your salesforce org which can be used to get a SessionId.
  • Import Enterprise/Partner WSDL file into the project and generate client side stubs
  • Import “SuryaDhruvsoftWebservice.wsdl” file into the project and generate client side stubs by right clicking on the WSDL file and click on “Generate Client”
  • The below image shows code generated for Partner WSDL in Blue color box and code for Custom Web Service (SuryaDhruvsoftWebservice.wsdl) in Red color box.

2

  • Create Servlet named as “ HandleWebService” with following code in your eclipse project
  • 344Create JSP page named as “AccessSalesforceCustomWS” with following code in your eclipse project

5

  • Run the above created JSP page and enter your name then click the submit button

Result:

67