0 votes
4 views
by

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

0 votes
by
 
Best answer

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).

Welcome to Memory Exceeded, where you can ask questions and receive answers from other members of the community.
You can donate any amount for Orphans village using following QR Code.
...