Is it possible to send a response message from a rest webservice? I have the following :
@RestResource(urlMapping='/*')
global with sharing class RestResource {
@HttpGet
webservice static List<Contact> showContact() {
Boolean isValid;
String phone;
List<Contact> resultCon= new List<Contact>();
RestRequest request = RestContext.request;
RestResponse response = RestContext.response;
try {
phone = (request.requestURI.substring(request.requestURI.lastIndexOf('/')+1)).replaceAll('[^0-9]','');
isValid = Regex_Validator.isValidPhone(phone);
system.debug('isValid '+ isValid);
resultCon = [SELECT id, phone , lastname FROM Contact WHERE phone = :phone];
} catch(exception e) {
system.debug('Error'+ e);
}
system.debug(resultCon);
if(resultCon.IsEmpty()) {
response.statusCode = 204;
response.addHeader('Content-Type', 'text/plain');
response.responseBody = blob.valueOf('Sorry no match');
}
if(!isValid) {
response.statusCode = 415;
response.responseBody = Blob.valueOf('Check format phonenumber :+00 0000000000');
}
if(!resultCon.IsEmpty()) {
return resultCon;
}else {
return null;
}
}
}
The statuscode is returned fine in workbench but the body is not!?