I have created an apex rest httppost class. This requires two parameters which are passed via response. I am trying to test this via workbench by passing two parameters.

global class OppDetails 
    global static void getDetails()
            RestRequest     request    = RestContext.request;
            RestResponse    response   = RestContext.response;
            Opportunity opp = (Opportunity)JSON.deserialize(request.requestBody.toString(),Opportunity.class);
            System.debug('----myopp: '+ opp);
        catch(Exception ex)


The JSON deserialized value is empty even though I am passing two values.

I am not sure how to test this using postman but this is how I am testing via workbench. My idea is to get both the parameter values and then insert based on ID.

Workbench Screenshot

Debug logs show Response body as null.

RestResponse:[headers={}, responseBody=null, statusCode=null]

1 Answer 1


That's because you don't have any the fields opportunityId or customerId` in your opportunity object, and you are using the opportunity sobject class to deserialize. You should only pass the field that are on your object if you want to use the opportunity sobject class.

{ "Id": "006...", "AccountId": "001..." }

Also you should check request body for what you are getting from workbench not response body. You did not set a response body, so the response in workbench would be empty.

  • I edited your answer to be more assertive and add some clarification. Please feel free to review and make any further adjustments if you'd like.
    – sfdcfox
    Commented Apr 12, 2020 at 15:43
  • @sfdcfox thankyou
    – User6670
    Commented Apr 12, 2020 at 15:46
  • Thanks @sfdcfox , I was not passing the exact field names as they exist in Opportunity object. Now, its working. Commented Apr 13, 2020 at 6:00

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .