+ Start a Discussion
Ikram Momin 16Ikram Momin 16 

searching usecase where salesforce returns List of error object in response

We are searching for usecase where salesforce returns multiple error object in result response.
below is ideal response we are searching for :
<updateResponse>
         <result>
            <errors>
               <fields>ProfileId</fields>
               <message>You can only assign profiles that are compatible with the user's license. For a list of compatible licenses and profiles, see the Salesforce Help.: Profile ID</message>
               <statusCode>FIELD_INTEGRITY_EXCEPTION</statusCode>
            </errors>
            <errors>
               <message>Changing User Type from High Volume Portal to New ICS Support Agents is not allowed. Select a different profile.</message>
               <statusCode>FIELD_INTEGRITY_EXCEPTION</statusCode>
            </errors>
            <id xsi:nil="true" />
            <success>false</success>
         </result>
      </updateResponse> 

can any one help us which provisioning will provide above single response ?      
AnudeepAnudeep (Salesforce Developers) 
As far as I know, there will only be one statusCode at any given time. In such scenarios, we handle the exception in the below manner
 
@RestResource(urlMapping='/mypath/*')
global without sharing class MyRest {
  
    @HttpGet 
    global static void get() {
        RestResponse res = RestContext.response;
        if (res == null) {
            res = new RestResponse();
            RestContext.response = res;
        }
        try {
            res.responseBody = Blob.valueOf(JSON.serialize(doGet()));
            res.statusCode = 200;
        } catch (EndUserMessageException e) {
            res.responseBody = Blob.valueOf(e.getMessage());
            res.statusCode = 500;
        } catch (Exception e) {
            res.responseBody = Blob.valueOf(
                    String.valueOf(e) + '\n\n' + e.getStackTraceString()
                    );
            res.statusCode = 500;
        }
    }

    private static Object doGet() {
        ...
    }
}

 
Ikram Momin 16Ikram Momin 16

Hi Anudeep

we are fine with OneStatusCode. We want multiple <message>
can you tell when we get below error message

Changing User Type from High Volume Portal to New ICS Support Agents is not allowed. Select a different profile.

Thanks