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;

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!

| improve this answer | |
  • 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 '13 at 18:44

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.