Sunday, 2 September 2012

Handling Exceptions In REST API wrappers in salesforce and setting proper HTTP error in header of HTTP response sent from Salesforce

To set the proper error code in the response packet returned from salesforce there is default HTTP error code table

The documentation of valid http error codes supported is in the http response is accessed on clicking below Documentation on HTTP error codes

To handle this in code here is a below simple example that demonstrates how to set the HTTP error codes in salesforce

global with sharing class accountrest {
global static Account getMerchandiseById() {
RestRequest req = RestContext.request;
RestResponse res=RestContext.response;
Account result;
String accId = req.requestURI.substring(
  result =[SELECT Name,AccountNumber,NumberofLocations__c FROM Account WHERE Id = :accId];
catch(exception e){
res.statusCode=400;//clear that error was due to account ID missing and hence BAD request
return result;


  1. Thankyou for sharing this.
    Web Designing Company In Chandigarh-Robtechworld cares about understanding you and your customers.
    Website Designing Company In Chandigarh

  2. Thank you for sharing this.
    The objective of this PG Diploma course is to provide the candidates with the best Detail knowledge and skills in the Process Safety Engineering discipline to facilitate faster learning curves while on the job.
    Process Safety Engineering Course


Introducing Lightning Base Components

Lightning Base Components are great addition to the platform and in fact revolutionary .One of the concerns around lightning component ...