function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
ForceComForceCom 

Type is not visible: httpcalloutmock

Hi ,

I am trying to create a mock response for Http request , I receive the compile error as display below.
Type is not visible: httpcalloutmock

The class is :

@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://test.bhtp.com/api/quotes', req.getEndpoint());
        System.assertEquals('Post', req.getMethod());
       
        // Create a fake response
        HttpResponse res = new HttpResponse();
        res.setHeader('Content-Type', 'application/json');
        res.setBody(mockJSON);
        res.setStatusCode(200);
        return res;
    }
}

Any help would be appreciated .

Thank you
kiranmutturukiranmutturu
Where you are initialized this variable mockJSON?
ForceComForceCom
@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.
       string mockJSON =''{[foo, bar]}";
       System.assertEquals('http://test.bhtp.com/api/quotes', req.getEndpoint());
        System.assertEquals('Post', req.getMethod());
      
        // Create a fake response
        HttpResponse res = new HttpResponse();
        res.setHeader('Content-Type', 'application/json');
        res.setBody(mockJSON);
        res.setStatusCode(200);
        return res;
    }
}
hi , I have initialized above the assert statements, but I don't think that is causing the problem ?
Katia HageKatia Hage
Did you by any chance create a custom class with the same name of httpcalloutmock?
Katia HageKatia Hage
I tried your sample but don't get this error. Also, the value for mockJSON should be within single quotes.
ForceComForceCom
It is really wierd that it got compiled now , me changing nothing !!!