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
sumit dsumit d 

Error:_Methods defined as TestMethod do not support Web service callouts in test class

Hi all,
    I have a helper class in which i dont have any callout still i am gettimg this error:-Methods defined as TestMethod do not support Web service callouts.
how to solve this error?
My test class is given below:-
@istest
private class Trigger_LogTest {
    
    private class Mock implements HttpCalloutMock {
        
        public HTTPResponse respond(HTTPRequest req) {
            
            HTTPResponse res = new HTTPResponse();
            
            res.setStatusCode(200);
            res.setBody('{'+
                        '  \"agenda\": \"Test Webinar\",'+
                        '  \"created_at\": \"2020-04-15T11:16:58Z\",'+
                        '  \"duration\": 60,'+
                        '  \"host_id\": \"BhN6PRjkQW-iUc8-8-aTSw\",'+
                        '  \"id\": 94298132774,'+
                        '  \"join_url\": \"https://zoom.us/j/94298132774?pwd=REZsT1NnOFd5aWhUUDB0cTFRS010dz09\",'+
                        '  \"password\": \"avfhfgh\",'+
                        '  \"registration_url\": \"https://zoom.us/webinar/register/WN_BRg795wbTHSIOWEnknY5gA\",'+
                        '  \"settings\": {'+
                        '    \"allow_multiple_devices\": false,'+
                        '    \"alternative_hosts\": \"\",'+
                        '    \"approval_type\": 0,'+
                        '    \"audio\": \"both\",'+
                        '    \"auto_recording\": \"none\",'+
                        '    \"close_registration\": true,'+
                        '    \"contact_email\": \"steve@realintelligence.com\",'+
                        '    \"contact_name\": \"Steve Kompolt\",'+
                        '    \"enforce_login\": false,'+
                        '    \"enforce_login_domains\": \"\",'+
                        '    \"global_dial_in_countries\": ['+
                        '      \"US\"'+
                        '    ],'+
                        '    \"global_dial_in_numbers\": ['+
                        '      {'+
                        '        \"city\": \"Chicago\",'+
                        '        \"country\": \"US\",'+
                        '        \"country_name\": \"US\",'+
                        '        \"number\": \"+1 3126266799\",'+
                        '        \"type\": \"toll\"'+
                        '      },'+
                        '      {'+
                        '        \"city\": \"New York\",'+
                        '        \"country\": \"US\",'+
                        '        \"country_name\": \"US\",'+
                        '        \"number\": \"+1 6465588656\",'+
                        '        \"type\": \"toll\"'+
                        '      },'+
                        '      {'+
                        '        \"city\": \"Houston\",'+
                        '        \"country\": \"US\",'+
                        '        \"country_name\": \"US\",'+
                        '        \"number\": \"+1 3462487799\",'+
                        '        \"type\": \"toll\"'+
                        '      },'+
                        '      {'+
                        '        \"city\": \"San Jose\",'+
                        '        \"country\": \"US\",'+
                        '        \"country_name\": \"US\",'+
                        '        \"number\": \"+1 6699009128\",'+
                        '        \"type\": \"toll\"'+
                        '      },'+
                        '      {'+
                        '        \"city\": \"\",'+
                        '        \"country\": \"US\",'+
                        '        \"country_name\": \"US\",'+
                        '        \"number\": \"+1 2532158782\",'+
                        '        \"type\": \"toll\"'+
                        '      },'+
                        '      {'+
                        '        \"city\": \"\",'+
                        '        \"country\": \"US\",'+
                        '        \"country_name\": \"US\",'+
                        '        \"number\": \"+1 3017158592\",'+
                        '        \"type\": \"toll\"'+
                        '      }'+
                        '    ],'+
                        '    \"hd_video\": true,'+
                        '    \"host_video\": true,'+
                        '    \"meeting_authentication\": false,'+
                        '    \"on_demand\": false,'+
                        '    \"panelists_video\": true,'+
                        '    \"post_webinar_survey\": false,'+
                        '    \"practice_session\": true,'+
                        '    \"question_answer\": true,'+
                        '    \"registrants_confirmation_email\": true,'+
                        '    \"registrants_email_notification\": true,'+
                        '    \"registrants_restrict_number\": 0,'+
                        '    \"show_share_button\": true'+
                        '  },'+
                        '  \"start_time\": \"2020-09-20T06:59:00Z\",'+
                        '  \"start_url\": \"https://zoom.us/s/94298132774?zak=eyJ6bV9za20iOiJ6bV9vMm0iLCJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhdWQiOiJjbGllbnQiLCJ1aWQiOiJCaE42UFJqa1FXLWlVYzgtOC1hVFN3IiwiaXNzIjoid2ViIiwic3R5IjoxMDAsIndjZCI6ImF3MSIsImNsdCI6MCwic3RrIjoicm5JSzZ3VDNsQnh2ODdMQUg0RTFsZU1OOVFwcldNZ2VIMUhzWnRaNXE3NC5CZ1VzZDBWRWFUUk9lVWR1VkVSWGIxbFpWRkZNVGpKUmRsQldhWHBQZG5OT2J6bHFabmR6TVZaUVNtVkRTVDFBWkRZeVpEZ3hOMll3WVdFMk16WTRNalJsWldRd1pETXhZakZoWldJMk1tWTFNR1UyTXpFNU5HVXdNalZrWXpnek56WTFNR05oTUdSbU1EWXdZMll6T0FBTU0wTkNRWFZ2YVZsVE0zTTlBQU5oZHpFIiwiZXhwIjoxNTg2OTU2NjE4LCJpYXQiOjE1ODY5NDk0MTgsImFpZCI6ImtCQnVrUUQwUjRlaE9Lb00wWU80TmciLCJjaWQiOiIifQ.t-ECUWaekV1eRkBwA00XR0ysKz0OHSUagnwT7guXkg8\",'+
                        '  \"timezone\": \"America/Los_Angeles\",'+
                        '  \"topic\": \"Test Webinar\",'+
                        '  \"type\": 5,'+
                        '  \"uuid\": \"iTfCvg3iSQW3oFjwObnLog==\"'+
                        '}');
            
            return res; 
        }
    }
  
    static testmethod void rollupForBoothTest(){
        Test.setMock(HttpCalloutMock.class, new Mock());

         rie__Zoom_User__c z = new rie__Zoom_User__c();
        z.rie__Email_Id__c = 'real@gmail.com';
        z.rie__FirstName__c = 'Real';
        z.rie__LastName__c = 'Int';
        z.rie__User_Type__c ='Licensed';
        insert z;
        
        Contact c = new Contact();
        c.LastName = 'steven';
        c.rie__Zoom_User__c = z.id;
        insert c;
        
        rie__Event__c evt = new rie__Event__c();
        evt.rie__Event_Time_Zone__c = '(GMT-07:00) Pacific Daylight Time (America/Los_Angeles)';
        insert evt;
        
        
        rie__Session__c s = new rie__Session__c();
        s.rie__Session_Status__c = 'Ready to Publish';
        s.rie__Date_Time__c = System.today();
        s.rie__Session_Organizer__c = c.id;
        s.rie__Publish_to_Web__c = False;
        s.rie__Session_End_Time__c = System.today();
        s.rie__Meeting_ID__c = '86023030645' ;
        s.rie__Meeting_Password__c = '53b347b2a5';
        s.rie__Event__c =  evt.id;
        insert s;
        
        ri__Campus__c campus = new ri__Campus__c();
        insert campus;
        
        ri__Property__c tradeShow = new ri__Property__c();
        tradeShow.ri__Campus__c = campus.id;
        insert tradeShow;
        
        ri__Unit__c booth = new ri__Unit__c();
        booth.ri__Building__c = tradeShow.id;
        insert booth;
        
        rie__Registration__c attendee = new rie__Registration__c();
        attendee.rie__Event__c = evt.id;
        insert attendee;
        
        rie__Log__c logs = new rie__Log__c();
        logs.rie__Event__c = evt.id;
        logs.rie__Session__c = s.id;
        logs.rie__Attendee_Chat__c = true;
        logs.Booth_Sponsor__c = booth.id;
        logs.rie__Attendee_Connect__c = true;
        logs.Booth_Sponsor_Chat__c = true;
        logs.Booth_Sponsor_Connect__c = true;
        logs.rie__Registration__c = attendee.id;
        insert logs;
         test.startTest();
        delete logs;
        test.stopTest();}}

My class is given below:-
/**
 * Helper Class For Trigger: Trigger_Log 
 */
public without sharing class LogTriggerHelper{
    public static List<rie__Log__c> newLogs;
    public static List<rie__Log__c> oldLogs;
    public static Map<Id, rie__Log__c> newMapLogs;
    public static Map<Id, rie__Log__c> oldMapLogs;
    
    public static boolean runTrigger = TRUE;
    
    public static Map<Id, rie__Registration__c> mapParentRegisTrationsToUpdate = new Map<Id, rie__Registration__c>();
    
    public static Map<Id, rie__Registration__c> mapParentBoothSponsorsToUpdate = new Map<Id, rie__Registration__c>();
    
    public static void rollupCalculations(){
        
        mapParentBoothSponsorsToUpdate = new Map<Id, rie__Registration__c>();
        rollupForBooth();
        if( mapParentBoothSponsorsToUpdate.size() > 0 ) {
            mapParentRegisTrationsToUpdate.putAll( mapParentBoothSponsorsToUpdate );
        }
        
        // update registrations
        if( mapParentRegisTrationsToUpdate.size() > 0 ) {
            update mapParentRegisTrationsToUpdate.values();
        }
    }
    
    public static void rollupForBooth(){
        
        Set<Id> parentRegistrationIds = new Set<Id>();
        if( Trigger.isInsert || Trigger.isUpdate || Trigger.isUndelete ){
            for( rie__Log__c logObj : newLogs ){
                if( logObj.rie__Registration__c != Null ){
                    parentRegistrationIds.add( logObj.rie__Registration__c );
                }
            }
        } 
        else if( Trigger.isDelete ) {
            for( rie__Log__c logObj : oldLogs ){
                if( logObj.rie__Registration__c != Null ){
                    parentRegistrationIds.add( logObj.rie__Registration__c );
                }
            }    
        }
        
        if( parentRegistrationIds.size() > 0 ){
            for( Id registrationId : parentRegistrationIds ) {
                rie__Registration__c parentBoothSponsor = new rie__Registration__c( Id = registrationId ); 
                parentBoothSponsor.rie__Booth_Counter__c = 0;
                parentBoothSponsor.rie__Booth_Chat_Counter__c = 0;
                parentBoothSponsor.rie__Booth_Connect_Counter__c = 0;
                mapParentBoothSponsorsToUpdate.put( parentBoothSponsor.Id, parentBoothSponsor );
            }    
            
            List<AggregateResult> aggrList = [ SELECT rie__Registration__c parentBoothSponsor, 
                                               COUNT(Id) boothSponsor
                                               FROM rie__Log__c
                                               WHERE rie__Registration__c IN: parentRegistrationIds
                                               AND Booth_Sponsor__c != Null
                                               GROUP BY rie__Registration__c ];
            for( AggregateResult ag :  aggrList ){
            
                Id parentBoothSponsorId = (String)ag.get('parentBoothSponsor');
                rie__Registration__c parentBoothSponsor = mapParentBoothSponsorsToUpdate.get( parentBoothSponsorId );
                                            
                parentBoothSponsor.rie__Booth_Counter__c = (Decimal)ag.get( 'boothSponsor' );
                mapParentBoothSponsorsToUpdate.put( parentBoothSponsor.Id, parentBoothSponsor );   
            }
            
            List<AggregateResult> aggrListChat = [ SELECT rie__Registration__c parentBoothSponsor, 
                                                   COUNT(Id) chatBoothSponsor
                                                   FROM rie__Log__c
                                                   WHERE rie__Registration__c IN: parentRegistrationIds
                                                   AND Booth_Sponsor__c != Null
                                                   AND Booth_Sponsor_Chat__c = TRUE
                                                   GROUP BY rie__Registration__c ];
            for( AggregateResult ag :  aggrListChat ){
            
                Id parentBoothSponsorId = (String)ag.get('parentBoothSponsor');
                rie__Registration__c parentBoothSponsor = mapParentBoothSponsorsToUpdate.get( parentBoothSponsorId );
                                            
                parentBoothSponsor.rie__Booth_Chat_Counter__c = (Decimal)ag.get( 'chatBoothSponsor' );
                mapParentBoothSponsorsToUpdate.put( parentBoothSponsor.Id, parentBoothSponsor );   
            }
            
            List<AggregateResult> aggrListConnect = [ SELECT rie__Registration__c parentBoothSponsor, 
                                                      COUNT(Id) connectBoothSponsor
                                                      FROM rie__Log__c
                                                      WHERE rie__Registration__c IN: parentRegistrationIds
                                                      AND Booth_Sponsor__c != Null
                                                      AND Booth_Sponsor_Connect__c = TRUE
                                                      GROUP BY rie__Registration__c ];
            for( AggregateResult ag :  aggrListConnect ){
            
                Id parentBoothSponsorId = (String)ag.get('parentBoothSponsor');
                rie__Registration__c parentBoothSponsor = mapParentBoothSponsorsToUpdate.get( parentBoothSponsorId );
                                            
                parentBoothSponsor.rie__Booth_Connect_Counter__c = (Decimal)ag.get( 'connectBoothSponsor' );
                mapParentBoothSponsorsToUpdate.put( parentBoothSponsor.Id, parentBoothSponsor );   
            }
        }
    }
}
can anyone help me with this error?
     
AbhishekAbhishek (Salesforce Developers) 
Hi,

This error occurs because web service callouts are not allowed in Test class. To bypass callouts add HttpcalloutMock class. Here is a sample test class with the mock class to bypass web services Callout. The mock class will take care of web services callouts.

For your reference,

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

https://salesforce.stackexchange.com/questions/31808/method-defined-as-testmethod-do-not-support-web-service-callouts-test-skipped

I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.

Thanks.
sumit dsumit d
Hi,
i have created a mock class in my test class  above, but still i am getting this error.can you help me with this? i am not making callout in my class.
Also the response i am using is coorect or not ? or should i use another response?
Please help.