Last active
August 29, 2015 14:09
-
-
Save lkatney/d7bdd012650a83afee73 to your computer and use it in GitHub Desktop.
Apex rest service to send JSONP response
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@RestResource(urlMapping='/Accounts/*') | |
global class AccountsService { | |
@HttpGet | |
global static void getAccounts() { | |
RestRequest req = RestContext.request; | |
RestResponse res = RestContext.response; | |
String callback = req.params.get('callback'); | |
String result; | |
try{ | |
List<Account> accs = [SELECT Id from Account LIMIT 0;] | |
} | |
if(!holidays.isEmpty()){ | |
result = JSON.serialize(accs); | |
} | |
}catch(Exception e){ | |
res.statusCode = 500; | |
result = '{"message" : "An error has encountered at server, Please try after some time!"}'; | |
} | |
} | |
res.addHeader('Content-Type','application/json; charset=utf-8'); | |
res.responseBody = Blob.valueOf(callback+'('+result+')'); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment