Skip to main content The Trailblazer Community will be unavailable from 2/1/2025 to 2/2/2025. Please plan your activities accordingly.
hi, I'm learning apex Rest web service.

i came across this code

@RestResource(urlMapping='/Account/*')

global with sharing class MyRestResource {

@HttpDelete

global static void doDelete() {

RestRequest req = RestContext.request;

RestResponse res = RestContext.response;

String accountId = req.requestURI.substring(req.requestURI.lastIndexOf('/')+1);

Account account = [SELECT Id FROM Account WHERE Id = :accountId];

delete account;

}

}

but im not able to understand what does

RestResponse res = RestContext.response;

Do

Can anybody tell what exactly RestResponse do with an example

Thanks,​​​​​​​​​​​​​​
1 answer
  1. Feb 13, 2020, 8:21 AM
    It looks like In this method they are not using RestResponse.Initialized but it is not used anywhere.

    RestResponse res = RestContext.response  is not doing anything here.

    Usually RestResponse object is used to pass data from an Apex RESTful Web service method to an HTTP response.

    Please refer below link which might help you in this

    https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_methods_system_restresponse.htm

    Hope this helps you

    Let me know if this helps you. Kindly mark it as solved so that it may help others in future.

    Thanks and Regards
0/9000