You need to sign in to do that
Don't have an account?
kpn
I wanted to get the response as XML? How should I do this?
In the above snippet, the return type is List<sObject> and when I do the API request with .json at the end, I'm getting JSON response and if with .xml at the end, then I'm getting the XML response.
i.e., /services/apexrest/v1/organizations.json - Gives JSON response,
/services/apexrest/v1/organizations.xml - gives XML response.
Why the same is not working in the first snippet (where the return type is Void and setting the response to the responseBody)?
JSON / XML Response in REST API
@RestResource(urlMapping='/v1/organizations') global with sharing class OrganizationInfoClass { @HttpGet global static void doGet() { RestResponse response = RestContext.response; List<Organization> OrgList = [SELECT Id, Name, IsSandbox FROM Organization limit 1]; response.statusCode = 200; response.responseBody = Blob.valueOf(JSON.serialize(OrgList)); } }
I wanted to get the response as XML? How should I do this?
@RestResource(urlMapping='/v1/organizations') global with sharing class OrganizationInfoClass { @HttpGet global static List<Organization> doGet() { RestResponse response = RestContext.response; List<Organization> OrgList = [SELECT Id, Name, IsSandbox FROM Organization limit 1]; return OrgList; } }
In the above snippet, the return type is List<sObject> and when I do the API request with .json at the end, I'm getting JSON response and if with .xml at the end, then I'm getting the XML response.
i.e., /services/apexrest/v1/organizations.json - Gives JSON response,
/services/apexrest/v1/organizations.xml - gives XML response.
Why the same is not working in the first snippet (where the return type is Void and setting the response to the responseBody)?
http://salesforce.stackexchange.com/questions/88771/what-xml-support-salesforce-provides-in-apex
All Answers
Also, if you just take a look into this https://developer.salesforce.com/forums/?id=906F00000009AtFIAU they are setting the response Content-type, but this is not working as well.. Am not sure what I'm doing wrong.. Or Am I trying something that is not possible?
http://salesforce.stackexchange.com/questions/88771/what-xml-support-salesforce-provides-in-apex