Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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;
share|improve this question
up vote 3 down vote accepted

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!

share|improve this answer
I wouldn't rely on anything that generates a 500 continuing to do so - we try hard to fix all those! – metadaddy Feb 4 '13 at 18:44
thanks @metadaddy, bolded to reinforce – bigassforce Feb 4 '13 at 19:06

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.