Activity Forums Salesforce® Discussions How to cover POST method in test class in Salesforce?

  • Anuj

    Member
    September 4, 2020 at 3:51 pm

    You can use the following way to cover Post method.

    `@isTest
    static void testHttpPost() {
    // prepare test-data

    //As Per Best Practice it is important to instantiate the Rest Context
    RestRequest req = new RestRequest();
    RestResponse res = new RestResponse();
    req.requestURI = '/services/apexrest/Something'; //Request URL
    req.httpMethod = 'POST';

    RestContext.request = req;
    RestContext.response= res;

    Test.startTest();
    String actual = null;//HttpClass.updateCustomObject();
    Test.stopTest();

    System.assertEquals('expected value', actual, 'Value is incorrect');
    }`

Log In to reply.

Popular Salesforce Blogs

Popular Salesforce Videos