Take the 2-minute tour ×
Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It's 100% free, no registration required.

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

1 Answer 1

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
  Crypto.generateAesKey(0);
}

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');
  pageReference.setRedirect(false);
  return pageReference;
}

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

share|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
    
thanks @metadaddy, bolded to reinforce –  user320 Feb 4 '13 at 19:06

Your Answer

 
discard

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.