function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Juan NúñezJuan Núñez 

How can I change the HTTP status code on an apex Page?

Hi!

 

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 in a RESTful service, but we need this to be a Page.

 

How can I do this?

 

Thanks

Best Answer chosen by Admin (Salesforce Developers) 
Juan NúñezJuan Núñez

I finally found the (lack) of solution in:

Salesforce@Stackexchange

All Answers

Tanvir AnsariTanvir Ansari
Can you expand your question. The HTTP status processing is what is used for AJAX and for asynchronous database updates or application processing
Juan NúñezJuan Núñez

I'd need to be able in the action method of the controller to change the HTTP status of a Page.

 

This'd be the Page:

 

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

 This'd be the controller:

 

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;
    }
}

 

Juan NúñezJuan Núñez

I finally found the (lack) of solution in:

Salesforce@Stackexchange

This was selected as the best answer