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

LWC to LWC Communication using Lightning Messaging Service (Part - 2)

In my previous post ( previous post link ) we have learn how to create a Lightning Messaging Service with 6 steps and today we will use the ...