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
Abhiram Sheshadri 9Abhiram Sheshadri 9 

Getting Error while saving the following test class while doing APEX REST Callouts Trailhead module

Class : Standard stuff from salesforce

@isTest
private class AnimalsCalloutsTest {

    @isTest static  void testGetCallout() {
        // Create the mock response based on a static resource
        StaticResourceCalloutMock mock = new StaticResourceCalloutMock();
        mock.setStaticResource('GetAnimalResource');
        mock.setStatusCode(200);
        mock.setHeader('Content-Type', 'application/json;charset=UTF-8');
        // Associate the callout with a mock response
        Test.setMock(HttpCalloutMock.class, mock);
        // Call method to test
        HttpResponse result = AnimalsCallouts.makeGetCallout();
        // Verify mock response is not null
        System.assertNotEquals(null,result,
            'The callout returned a null response.');
        // Verify status code
        System.assertEquals(200,result.getStatusCode(),
          'The status code is not 200.');
        // Verify content type   
        System.assertEquals('application/json;charset=UTF-8',
          result.getHeader('Content-Type'),
          'The content type value is not expected.');  
        // Verify the array contains 3 items     
        Map<String, Object> results = (Map<String, Object>) 
            JSON.deserializeUntyped(result.getBody());
        List<Object> animals = (List<Object>) results.get('animals');
        System.assertEquals(3, animals.size(),
          'The array should only contain 3 items.');          
    }   

}

While saving getting 

Error: Compile Error: Method does not exist or incorrect signature: [StaticResourceCalloutMock].setStaticResource(String) at line 7 column 9
Best Answer chosen by Abhiram Sheshadri 9
RAM AnisettiRAM Anisetti
Hey Abhi,
Please check any class is exist in your org having same name of StaticResourceCalloutMock.
if it is there please remove or rename it.

All Answers

RAM AnisettiRAM Anisetti
Hi,
Check once Static Resource Name in Your Org .compare both names are same are not in the line mock.setStaticResource('GetAnimalResource');
Abhiram Sheshadri 9Abhiram Sheshadri 9
Hi RAM,

I checked the Static Resource name in the org, it's exactly same as the one I have passed as a string to the ​setStaticResource() method. Don't know what the issue is.

Thanks,
Abhiram
RAM AnisettiRAM Anisetti
Hey Abhi,
Please check any class is exist in your org having same name of StaticResourceCalloutMock.
if it is there please remove or rename it.
This was selected as the best answer
Abhiram Sheshadri 9Abhiram Sheshadri 9
Thanks, RAM,

Found a class by mistake I had created with the same name. That solves and have passed the challenge.