I am creating a rest Service and its integrated with external system and sending data to external system through lightning component and its working fine while sending the data from Salesforce. while sending data to external system, it will redirect to external system.

In the same way, I need to get the data from external system to Salesforce through hook page. While sending data from external system, it needs to redirect to salesforce page where I was tried to send data from salesforce.

My apex rest service

global without sharing class test{

    global static String doPost()

        RestRequest req=RestContext.request;
        RestResponse res=RestContext.response;
        Blob body = req.requestBody;

        Map<String,String> params = RestContext.request.params;

        return null ;



this my hook page but i want to redirect to salesforce record detail page

enter image description here

please anybody help on this

  • 1
    APIs are not usually built for purpose to redirect to a resource, instead those are built as a web service to allow two different systems to communicate and exchange data. What is your use case and why do you need to redirect a URL where not necessarily all consumers of the API will have access to that URL? – Jayant Das Nov 16 '18 at 14:56
  • I am able to pass the data to external system from Salesforce where i am using a component button to send data. In the same way I need data from the same external system and while sending the data from external system to salesforce through Hook page, it needs to redirect to the same salesfroce page where I was used to send to data. – Test userADG23 Nov 16 '18 at 15:10
  • @JayantDas, one more question from me. In the rest service class, Is it possible to redirect to a record detailed of a object using an record?(assume that the record will get in class) – Test userADG23 Nov 16 '18 at 15:14

You are interpreting this incorrectly. APIs are not built for the use case (redirecting to a resource) that you are trying to solve. APIs are web services where they receive a request and return a response and it's up to the caller of the API as what they want to do further with the response.

If I understand this correctly you want to invoke a REST API exposed from Salesforce and that the caller should be navigated to a particular record page. This is not the correct implementation approach. You cannot redirect to a page from your service. Let's say even if you were able to redirect to a page from your service, the caller of the service would never know that because they will only receive a response back from the service.

Your implementation approach here should be to provide a response back to the caller with the absolute url of the record page as a response, and then let the caller decide if they want to redirect it to the resource or not.

| improve this answer | |
  • let me explain clearly. I have implemented rest service and accessing API via force.com site and external system invoking this service with site URL. Whenever external system send the response with service URL we are creating or updating few objects. After execution is completed then it should be redirect to Opportunity or Contact Detail page. Any solution for this requirement? Please let me know on this. – Test userADG23 Nov 18 '18 at 13:56

I faced the same issue wherein the response, I need to direct to a different page. I used 301 redirection functionality of the browser. The following code will force the browser to redirect to a different page.

global class MyRestService {
global static String doGet() {
    String paramValue = RestContext.request.params.get('param1');
    // Do something
   RestContext.response.statusCode = 301;
   return null;
| improve this answer | |

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.