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,
###############################################
###############################################
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 :
- Method should be define with "webservice static"
- Class should be declared as "global"
- Following elements should not be the web service method's parameters
- Maps
- Sets
- Pattern objects
- Matcher objects
- Exception objects