Thursday, May 4, 2017

SOAP Web Service Example in Apex.

Exposing Apex Methods as SOAP Web Services is very simple.

Scenario : Suppose we have a custom Employee Object having 2 properties Name and Roll Number.
Now we want to create a web method or web service method, which will take employee name and roll number as parameters and Insert the record in Employee Object.

Below is a simple example for the above scenario,

###############################################
global class MyWebService {

webservice static String createEmployeeRecord(String empName, Integer empRollNo){
    if(empName != null && empName.trim().length() > 0 && empRollNo != null && empRollNo > 0){
      Employee__c empIns = new Employee__c(Name__c = empName, Roll_Number__c = empRollNo);
      try{
            INSERT empIns;
      }catch(DmlException e){
            System.debug('Error while performing Employee insertion.');
            return 'FAILURE';
      }
      return 'SUCCESS';
    }else{
            return 'FAILURE';
    }
  }
}
###############################################
Considerations :

  1. Method should be define with "webservice static"
  2. Class should be declared as "global"
  3. Following elements should not be the web service method's parameters
  •          Maps
  •          Sets
  •          Pattern objects
  •          Matcher objects
  •          Exception objects

Data Cloud Part 6: Practical (Ingest Physical Store's Customer details and Sales details)

Hope you have already created your Data Cloud Org and also downloaded the Customer's details and Sales details from previous posts.  Now...