Activity Forums Salesforce® Discussions How do you create a test class for a callout in Salesforce?

  • Aditya

    Member
    September 5, 2020 at 8:04 am

    <pre id="ext-gen27">@isTest
    global class MockHttpResponseGenerator implements HttpCalloutMock {
    // Implement this interface method
    global HTTPResponse respond(HTTPRequest req) {
    // Optionally, only send a mock response for a specific endpoint
    // and method.
    System.assertEquals('http://example.com/example/test', req.getEndpoint());
    System.assertEquals('GET', req.getMethod());

    // Create a fake response
    HttpResponse res = new HttpResponse();
    res.setHeader('Content-Type', 'application/json');
    res.setBody('{"example":"test"}');
    res.setStatusCode(200);
    return res;
    }
    }

Log In to reply.

Popular Salesforce Blogs

Popular Salesforce Videos