function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Luke Higgins 23Luke Higgins 23 

How to redirect to URL from webservice method

After clicking a link to create a record, I'm trying to redirect to a landing page. Currently, it just takes the user to an XML file tree. Here is the code I currently have - 
 
@RestResource(urlMapping='/approve/*')
global with sharing class exAppClass {
  jstcl__TG_Timesheet__c ts = new jstcl__TG_Timesheet__c();
        // GET request
       @HttpGet
        global static jstcl__TG_Timesheet__c doGet() {
          RestRequest req = RestContext.request;
          RestResponse res = RestContext.response;
          String tsid = req.requestURI.substring(req.requestURI.lastIndexOf('/')+1);

          jstcl__TG_Timesheet__c ts = [SELECT Id, jstcl__Week_Ending__c FROM jstcl__TG_Timesheet__c WHERE Id = :tsid];
          getCalloutResponseContents();
          insertLog(ts);
          return ts;
        }
        private static Express_Approval_Log__c insertLog(jstcl__TG_Timesheet__c ts){
          Express_Approval_Log__c log = new Express_Approval_Log__c();
          log.Name = 'EAL '+ts.jstcl__Week_Ending__c;
          log.Timesheet__c = ts.Id;
          log.Approval_Date_Time__c= DateTime.now();
          log.Status__c = 'Approved';
          insert log;
          return log;
      }
      public static PageReference getCalloutResponseContents() {
        PageReference pageRef = new PageReference('https://testURL.com');
      return pageRef;
        }
        
}

The getCalloutResponseContents() is not redirecting to the URL provided
AbhishekAbhishek (Salesforce Developers) 
Ideally, the redirection should happen at the caller side. You can pass the URL to redirect.

I hope you find the above information is helpful. If it does, please mark as Best Answer to help others too.

Thanks.