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
Shruti Suman MishraShruti Suman Mishra 

Hi, I need to cover method returning Blob type data in code coverage. Require urgent help on this.

 public Blob getURLAttachment(string docurl){
            String remoteContentURL=docurl;
            Http http=new Http();
            Httprequest request=new Httprequest();
            request.setEndpoint(remoteContentURL);
            request.setMethod('GET');
            request.setTimeout(120000);
            Httpresponse response= http.send(request);
            Blob remoteContentAsBlob=response.getBodyAsBlob();   
           return remoteContentAsBlob;
    } 
Alexander TsitsuraAlexander Tsitsura
Hi Shruti

You need use HttpCalloutMock and setup failed callout response
Please read documentation aboud it https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_classes_restful_http_testing_httpcalloutmock.htm

As a common practice, if your question is answered, please choose 1 best answer. 
But you can give every answer a thumb up if that answer is helpful to you.

Thanks,
Alex