Guest User

Untitled

a guest
Jul 16th, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.20 KB | None | 0 0
  1. @RestResource(urlMapping='/*')
  2. global with sharing class RestResource {
  3. @HttpGet
  4. webservice static void showContact() {
  5. Boolean isValid;
  6. String phone;
  7. List<Contact> resultCon= new List<Contact>();
  8. RestRequest request = RestContext.request;
  9. RestResponse response = RestContext.response;
  10.  
  11. try {
  12. phone = (request.requestURI.substring(request.requestURI.lastIndexOf('/')+1)).replaceAll('[^0-9]','');
  13. isValid = Regex_Validator.isValidPhone(phone);
  14. resultCon = [SELECT id, phone , lastname FROM Contact WHERE phone = :phone];
  15. response.addHeader('Content-Type', 'application/json');
  16. response.responseBody = Blob.valueOf(JSON.serialize(resultCon[0].id));
  17. } catch(exception e) {
  18. response.addHeader('Content-Type', 'text/plain');
  19. if(resultCon.IsEmpty()) {
  20. response.responseBody = Blob.valueOf('Sorry no match');
  21. }
  22. if(!isValid) {
  23. response.responseBody = Blob.valueOf('Check format phonenumber :+00 0000000000');
  24. }else{
  25. response.responseBody = Blob.valueOf('exception '+e);
  26. }
  27. }
  28. }
  29. }
Add Comment
Please, Sign In to add comment