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

Comments

  1. Very good work!!
    Clear and easy to understand.

    I need to use my service in MuleSoft. you can say i want to access it in post man.
    Can you please tell me How we call this salesforce web service from postman chrome plug-on?

  2. Thanks In Advance for any help.

    • Hi There,

      You make learning and reading addictive. All eyes fixed on you. Thank you being such a good and trust worthy guide.

      I am excited to announce a new guide format for content that helps make understanding Any point Platform and implementing typical integrations patterns much easier. With any point Platform, an organization can not only integrate any two systems together, but can also deploy, and manage those applications all from within a single platform.
      The goal of these guides is to teach you — the developer — how to wield the platform and gain a meaningful understanding on how to achieve success
      with your own projects

      I read multiple articles and watched many videos about how to use this tool – and was still confused! Your instructions were easy to understand and made the process simple.

      MuchasGracias,
      Lisa

  3. Emmett McLean says:

    Nice write up. I worked through it June 17th, 2015 on kepler.

    I installed the dependent web packages into eclipse – and those use Axis 1.4.6 to generate the stubs. Some of the classes and packages used in the generated files aren’t available in Axis2-1.6.2.

    The example would have been more if an additional method existed in the Salesforce WSDL – so we could see how arguments are passed to the Web Service and how complex types are parsed when they are returned.

  4. ramkrishna says:

    nice work …….. clear to understand

  5. Atul Rakate says:

    Thanks for the post it was helpful, but I’m getting error after entering the name in text box
    Error Please Check INVALID_SESSION_ID: Invalid Session ID found in SessionHeader: Illegal Session

  6. Abc Xyz says:

    How can we access the header at the SFDC end from Java system. Say, we have to sent some parameter through headers(like IP address), java can send those. However, at SFDC end, how we can access the same.

Leave a Reply to Abc Xyz Cancel reply

*