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
Daniel WretmanDaniel Wretman 

callout mock test class "incorrect signature"

Hi all
I have been working on the first ever http callout for me, so it is based on the stuff in the trail head. But I hit some sort of snag I can't get around, hope one of you guys can help out. It is all very basic for now, will add assertions etc when the basics compile fine.

Everything except one line compile fine, so the issue is in my test class where I test the mock callout, I get the following compilation error: "Method does not exist or incorrect signature: void sendRequest() from the type OPSImSendRequest". This is from the "testPostCallout"  and the row is: "HttpResponse response = OPSImSendRequest.sendRequest();"

This is my code:

trigger opsIMEvents on Case (before insert) {
    
    if(trigger.isAfter){
        
        for(case c : trigger.new){
            if(c.Status == 'RESOLVED'){
            
                opsIMEventsTriggerHandler.caseEventResolved(c.OPS_IM_record_Id__c, c.Id, c.resolved_by__c, c.Last_Status_Change__c);
                
            }
     }

public class opsIMEventsTriggerHandler {                    
                                                                
     @future(callout=true)
    
    public static void caseEventResolved(Id eventVCId,Id eventSFId, Id resolvedBy, DateTime lastStatusChange){

        String event_type='event_resolved';                     
        String id=eventVCId;                                    
        String salesforce_id=eventSFId;                            
        String resolve_by=resolvedBy;                            
        String timeStamp=string.valueOfGMT(lastStatusChange);            
         
        Map<String, String> data = new Map<String, String>();
        
        data.put('id',id);
        data.put('salesforce_id',salesforce_id);
        data.put('event_type',event_type);       
        data.put('resolve_by',resolve_by);
        data.put('timestamp',timeStamp);
        
         OPSImSendRequest.sendRequest(data);

    }
}

public class OPSImSendRequest {
    
    public static void sendRequest (map<string,string> data){
        
        Http http = new Http();
        HttpRequest req = new HttpRequest();
         
         req.setEndpoint('https://alert.xxx.com/integrations/generic/20131114/alert/$YOUR_API_KEY_HERE/$ROUTING_KEY_HERE');  //I know, this is not a valid end point...
         req.setMethod('POST');
        String body = JSON.serialize(data);
         System.debug(body);
         req.setBody(body);
         req.setHeader('Content-Type','application/json;charset=UTF-8');
        HTTPResponse res = http.send(req);
         System.debug(res.getBody());
    }
}

@isTest
global class MockOPSImSendRequest implements HttpCalloutMock{
    
    global HTTPResponse respond (HTTPRequest request){  
        
        HttpResponse response = new HttpResponse();
        response.setHeader('Content-Type', 'application/json');
        response.setStatusCode(200);
        return response;
        
    }
}

@isTest
    public static void testPostCallout() {
        
    Test.setMock(HttpCalloutMock.class, new MockOPSImSendRequest());
    
//    test.startTest();
    HttpResponse response = OPSImSendRequest.sendRequest();
//    test.stopTest();
           
        
    }
}


 
AbhishekAbhishek (Salesforce Developers) 
https://salesforce.stackexchange.com/questions/287025/method-does-not-exist-or-incorrect-signature-void-sendsystem-httprequest-from


https://developer.salesforce.com/forums/?id=9060G0000005boOQAQ


Try the suggestions mentioned above.
Daniel WretmanDaniel Wretman
Hi

I tried with that solution, it did not solve my complaton issue. Please see the change at line 14-15 here.

public class OPSImSendRequest {
    
    public static void sendRequest (map<string,string> data){
        
        HttpRequest req = new HttpRequest();
         
         req.setEndpoint('https://alert.xxx.com/integrations/generic/20131114/alert/$YOUR_API_KEY_HERE/$ROUTING_KEY_HERE');
         req.setMethod('POST');
        String body = JSON.serialize(data);
         System.debug(body);
         req.setBody(body);
         req.setHeader('Content-Type','application/json;charset=UTF-8');
        
//        HTTPResponse res = http.send(req);
        HttpResponse res = new Http().send(req);
        
         System.debug(res.getBody());
    }
}


Best regards
Daniel Wretman
Daniel WretmanDaniel Wretman
I actually tok some time to try the example in the trailhead, it get the same compilation error.....

https://trailhead.salesforce.com/content/learn/modules/apex_integration_services/apex_integration_rest_callouts