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
RohiniHRohiniH 

Send HTTP status code back ,[200, 500]

Hi All,

 

A third party sends notification data as parameters to our url , on verifying the data we either send HTTP status 200 OK on success or 500 Internal error otherwise.

 

How do we go about changing the HTTP status code when returning the pagereference in salesforce.

 

public PageReference initConfirmation(){

    respRES = System.currentPagereference().getParameters().get('RES');

    if( validate(respRES ) ){

         //send back HTTPSTATUS CODE 200

         //return null;

   }else{

       //Send back HTTP STATUS CODE 500 

      // PageReference pref = ApexPages.currentPage(); // do something

   }

}

 

Kind regards,

Rohini H

 

sfdcfoxsfdcfox

You would have to use a RestResource annotation and call it directly as a web service. As far as I'm aware, salesforce.com always generates a 200 OK request, even when an exception is thrown, etc. Using RestContext.response, you can specify a statusCode of any value that is accepted on the Internet, including 2xx, 3xx, 4xx, and 5xx messages.