How can I render a Visualforce page from an @HttpGet method?

HttpGet methods do not support return type of System.PageReference

My controller method looks like this:

global with sharing class CaseController {

    global static PageReference updateCase() {
        RestRequest req = RestContext.request;
        RestResponse res = RestContext.response;
        PageReference page = Page.CaseResponse;

        // do something

        return page;

Can I write a method that is called inside updateCase() to return the page? Is it even possible?


I realise I'm approaching it backward, but this was supposed to record a response in the URL params and render a page in response.

  • 1
    If you need to return a PageReference, you probably need an apex:actionFunction... – sfdcfox Oct 11 '18 at 3:57
  • What are you trying to achieve? – Sebastian Kessel Oct 11 '18 at 4:07
  • I updated the question with some info. – okay56k Oct 11 '18 at 4:08

You cannot return a PageReference from an Apex REST method. Refer to the below excerpt from the documentation:

These return and parameter types are allowed:

  • Apex primitives (excluding sObject and Blob).
  • sObjects
  • Lists or maps of Apex primitives or sObjects (only maps with String keys are supported).
  • User-defined types that contain member variables of the types listed above.

Furthermore, why would you really need it? The time you expose an API, you are not dealing with a UI component, but necessarily integration. It's upon the caller to decide what to do after they receive the response.

  • So I should switch it out for a SOAP method or something, right? – okay56k Oct 11 '18 at 3:58
  • No. That is not going to help either. I am not sure about your use case, but you are getting the overall API implementation wrong. APIs are exposed to provide an interface to external systems to be able to perform some operations in your system without the need of interacting through any GUI. – Jayant Das Oct 11 '18 at 4:01
  • I'm trying to leverage it to record a response in the params and render a page. I might have to rethink the approach. – okay56k Oct 11 '18 at 4:02

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.