Advertisement
Guest User

Untitled

a guest
Oct 23rd, 2014
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.81 KB | None | 0 0
  1. @RestResource(urlMapping='/mypath/*')
  2. global without sharing class MyRest {
  3.  
  4. @HttpGet
  5. global static void get() {
  6. RestResponse res = RestContext.response;
  7. if (res == null) {
  8. res = new RestResponse();
  9. RestContext.response = res;
  10. }
  11. try {
  12. res.responseBody = Blob.valueOf(JSON.serialize(doGet()));
  13. res.statusCode = 200;
  14. } catch (EndUserMessageException e) {
  15. res.responseBody = Blob.valueOf(e.getMessage());
  16. res.statusCode = 400;
  17. } catch (Exception e) {
  18. res.responseBody = Blob.valueOf(
  19. String.valueOf(e) + 'nn' + e.getStackTraceString()
  20. );
  21. res.statusCode = 500;
  22. }
  23. }
  24.  
  25. private static Object doGet() {
  26. ...
  27. }
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement