Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @RestResource(urlMapping='/*')
- global with sharing class RestResource {
- @HttpGet
- webservice static void 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);
- resultCon = [SELECT id, phone , lastname FROM Contact WHERE phone = :phone];
- response.addHeader('Content-Type', 'application/json');
- response.responseBody = Blob.valueOf(JSON.serialize(resultCon[0].id));
- } catch(exception e) {
- response.addHeader('Content-Type', 'text/plain');
- if(resultCon.IsEmpty()) {
- response.responseBody = Blob.valueOf('Sorry no match');
- }
- if(!isValid) {
- response.responseBody = Blob.valueOf('Check format phonenumber :+00 0000000000');
- }else{
- response.responseBody = Blob.valueOf('exception '+e);
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment