8

How I can see what the JSON response looks like for a REST service that looks like the one below? I guess I'm looking for the actual steps of what I need to do to see the JSON response.

@RestResource(urlMapping = '/BP_Routes/*')
global with sharing class BP_Routes {

    @HttpPost //Method name
    //Check for User Authentication based on UserName and Password from external system
    global static ResponseWrapper BP_Routes(string username) {

        String strStatusMsg = '';//Holds the status message
        Integer isSuccessRes;//Holds the success response '1' or '0'
        list<Routewrapper> lstRteWrap = new list<Routewrapper>();
        list<personRoutesWrapper> lstPrsnWrap = new list<personRoutesWrapper>();
        ...
12

You can head over Salesforce Workbench and use the REST Utility to test the endpoint .

enter image description here

Your endpoint to test will be

/services/apexrest/BP_Routes

Also looks like the method is accepting a string parameter ,so you will need to select post and then the JSON input is

{
  "username" : "test"
}

The response will tell you the JSON structure .Also just by looking into the ResponseWrapper class you will know the structure of the JSON .

5

IN exec anonymous simply type:

system.debug(BP_Routes.BP_Routes('APPROPRIATEUSERNAMEHERE'));

and it will debug what is returned. If you like you can serialize it since it is not serialized in your class:

system.debug(JSON.serializePretty(BP_Routes.BP_Routes('APPROPRIATEUSERNAMEHERE')));

And the other answers work as well, this is just pretty easy to do without leaving org

4

It will be based on the return type you are sending. For example your code is sending ResponseWrapper for HTTP-Post call with URL '/services/apexrest/BP_Routes'

Let's assume you have defined RepsonseWrapper structure as below -

global Class ResponseWrapper{
    public String statusCode;
    public Datetime responseOut;
    public Integer recordCount;
    public List<Map<String, String>> errorMessages;


    public ResponseWrapper(){}
}

The JSON response would be like as below -

{
    "statusCode":"ERROR",
    "responseOut":"2017-04-14T01:01:01.000Z",
    "recordCount":0,
    "errorMessages":[{"errorMessage":"Some Error Message","errorCode":"SOME_ERROR_CODE"}],
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.