I'm trying to develop a Page that given some GET parameters would return HTTP Status 200 or status 400 depending on some inner query.

This would be really easy with a RESTful service, but we need this to be a Page.

How can I do this?

This is the page:
<apex:page controller="SimpleRequest" action="{!Success}">...</apex:page>

And this is the SimpleRequest class:

public class SimpleRequest {
    public SimpleRequest(){}

    public PageReference Success() {
        Map<String,String> GET = ApexPages.currentPage().getParameters();

        if (GET.isEmpty()) {
            //return HTTP status code 400

            return null;

1 Answer 1


Even when an Apex exception is thrown, the page responds 200 OK :-(

If you can fail hard enough within Salesforce you might get 500 Internal Server Error:

static void failHard() {
  //HTTP/1.1 500 Server Error

But I think the only supported perversion of the HTTP status code is 302 Found:

public PageReference getRedirector() {
  PageReference pageReference = new PageReference('/home/home.jsp');
  return pageReference;

however this behaviour is not honoured when invoked from the action attribute of an apex:page!

  • 3
    I wouldn't rely on anything that generates a 500 continuing to do so - we try hard to fix all those!
    – metadaddy
    Feb 4, 2013 at 18:44

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .