1

I have a class with @restresource. To which a request is coming to insert the record. How can we identify what kind of request is coming in. Is it XML or JSON format. Is there any way to identify incoming request. Please help me if is possible.

  • Have you checked content-type of request? – SFIntegrator Mar 13 '15 at 7:53
  • Why do you want to know ? The abstraction salesforce offers implies that you shouldn't be needing to look at the low-level technical stuff. By explaining what you're trying to do, we can usuelly give you a better answer. – Samuel De Rycke Mar 13 '15 at 10:17
2

Unless you are working with the raw content, any parameters that your REST method has Salesforce will automatically attempt to de-serialize from the request body, so you wouldn't need to know the content type in that scenario.

If you do want to work with the raw content, then to determine the type you'd need to inspect the request object:

RestRequest req = RestContext.request;
String contentType = req.headers.get('Content-Type');

See Apex REST Methods and RestRequest Class documentation for more info.

1

Not sure about the method but type of request, JOSN or XML, should be predefined in data contract itself.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.