Apex

Creating Custom WebService in Salesforce

Creating Custom WebService in Salesforce

Creating Custom WebService in Salesforce

Apex Code supports the ability to expose Apex methods as a Web service. This help external clients to  invoke apex methods .  Apex also supports the ability to consume clients web Services and this process is known as Callouts. In this Article we will be focusing on Creating WebService and exposing it to the Clients.

Lets take an example in which a client would be invoking the Salesforce Webservice Method to create Accounts.

Step 1

First step is to create a Global Class as shown below. Why Global Class ?  Global Access modifier  makes the class visible everywhere and not only on the specified Application. 


global class AccountExample {

}

Step 2

global class AccountExample {

      webservice static void createAccount(String s) {
         
   account a= new account();
   a.name=s;
   insert a;
             
       }

}
Method createAccount creates a account in salesforce based on the parameter provided.
Salesforce has built in functionality which creates the WSDL from the webservice class. This
WSDL is given to the client who can consume it to make Calls to Salesforce.
Click on Generate WSDL button as shown on the snapshot below:



Click to see how to Test/Simulate Custom Webservice Using SOAP UI Tool


About Saurabh Dua

0 comments:

Post a Comment

Note: only a member of this blog may post a comment.

Powered by Blogger.