I have a requirement and I am not sure is it possible or not. My requirement is that I have a rest service class with @httpGet annotation where I am getting Id of a record after that I need to do rest post callout with that Id in the same transaction and that callout returns a location header which I need to use to create a response for rest service class. Any suggestion will be help very helpful.

1 Answer 1


If you look at the documentation for HttpResponse, you'll see that there are two methods that should interest you: getHeader(), and getHeaderKeys().

getHeaderKeys() gives you a list of strings. If a "location" header is given to you in the response, then it'll be one of the entries in that list. After confirming its existence, you could then call getHeader().

Your @RestResource class has access to the response that Salesforce will return to the caller of your apex REST class via RestContext.response, which is an instance of the RestResponse class. It has a public headers variable which is a Map<String, String> which you can add things to (such as your "location" header from the other callout).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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