@RestResource(urlMapping='/CreatingleadFromSite/*')
global class BookingWebService {
@HttpPost
global static BookingResponseWrapper createBooking(BookingWrapper Wrapper) {
BookingResponseWrapper brwObj = new BookingResponseWrapper(true,'');
Savepoint sp = Database.setSavepoint();
try{
lead ld = new lead();
ld = wrapper.ld;
if(ld !=null){
insert ld;
}
brwObj.isSuccess =True;
brwObj.message = 'Record Inserted Succesfully';
}
catch(exception e){
Database.rollback(sp);
brwObj.isSuccess =False;
brwObj.message = e.getMessage();
}
return brwObj;
}
}
@RestResource(urlMapping='/CreatingleadFromSite/*')
global class BookingWebService {
@HttpPost
global static BookingResponseWrapper createBooking(BookingWrapper Wrapper) {
BookingResponseWrapper brwObj = new BookingResponseWrapper(true,'');
Savepoint sp = Database.setSavepoint();
try{
lead ld = new lead();
ld = wrapper.ld;
if(ld !=null){
insert ld;
}
brwObj.isSuccess =True;
brwObj.message = 'Record Inserted Succesfully';
}
catch(exception e){
Database.rollback(sp);
brwObj.isSuccess =False;
brwObj.message = e.getMessage();
}
return brwObj;
}
}
BookingResponseWrapper:
This class holds the return values for our restresource class . this class holds two variables issuccess and message. when lead inserted succesfully we set this values to success otherwise in case of exception this will return error message.
global class BookingResponseWrapper {
Public Boolean isSuccess;
Public string message;
global BookingResponseWrapper(Boolean isSuccess,string message){
this.isSuccess = isSuccess;
this.message = message;
}
}
global class BookingResponseWrapper {
Public Boolean isSuccess;
Public string message;
global BookingResponseWrapper(Boolean isSuccess,string message){
this.isSuccess = isSuccess;
this.message = message;
}
}
global class BookingResponseWrapper {
Public Boolean isSuccess;
Public string message;
global BookingResponseWrapper(Boolean isSuccess,string message){
this.isSuccess = isSuccess;
this.message = message;
}
}
BookingWrapper:
This Class used to Hold the data for our BookingWebService class parameter . webservice get the input from wrapper class and on the basis of this input create lead.
global class BookingWrapper {
public Lead ld;
global BookingWrapper(lead ld){
this.ld = ld;
}
}
global class BookingWrapper {
public Lead ld;
global BookingWrapper(lead ld){
this.ld = ld;
}
}
global class BookingWrapper {
public Lead ld;
global BookingWrapper(lead ld){
this.ld = ld;
}
}
BookingWebService_TC:
test class for our rest resource class,
@istest
public class BookingWebService_TC {
public static testMethod voidTest1(){
lead ld = newlead(lastname = 'test',company ='testcompany');
My Name is Himanshu Rana, 23 Years young, born and grow up in Ghaziabad, India. A High Spirited Salesforce Admin, Developer and a Blogger. I currently work at Wakencode Technologies,