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
Dmitriy JediDmitriy Jedi 

Cannot complete Apex REST Callouts module

Have 100% coverage using AnimalLocatorMock.apxc class in my connected org, but got the error when check challenge: 

Challenge Not yet complete... here's what's wrong:
No Apex class named 'AnimalLocatorMock' was found.

Please help!!!
Best Answer chosen by Dmitriy Jedi
Marek Kosar_Marek Kosar_
I don't see any issue in you code, but check this out->
https://developer.salesforce.com/forums/?id=906F0000000MJiPIAW
Looks like the same problem (with solution), maybe it can help you.

All Answers

Marek Kosar_Marek Kosar_
Hi Dmitriy,

paste here your source code for this module and I belive someone will help you ;)
I passed this module without error, so I can check when you share your code.
James WooleyJames Wooley
.apxc is the extension for a lightning component controller. Shouldn't this be .cls?

Or if this is related to lightning development, see here for a user who had a similar issue and managed to resolve it:
http://salesforce.stackexchange.com/questions/92847/cant-set-lightning-component-controller
Dmitriy JediDmitriy Jedi
Ok, Marek thank you for quick respond. public class AnimalLocator { public static String getAnimalNameById(Integer animalId) { String animalName = ''; String endPointUrl = ' https://th-apex-http-callout.herokuapp.com/animals/' + String.valueOf(animalId); Http http = new Http(); HttpRequest request = new HttpRequest(); request.setEndpoint(endPointUrl); request.setMethod('GET'); HttpResponse response = http.send(request); // If the request is successful, parse the JSON response. String result = 'None'; if (response.getStatusCode() == 200) { String jsn = response.getBody(); result = jsn; System.debug(' --------------> ' + jsn); } return result; } } @isTest global class AnimalLocatorMock implements HttpCalloutMock { // Implement this interface method global HTTPResponse respond(HTTPRequest request) { // Create a fake response HttpResponse response = new HttpResponse(); response.setHeader('Content-Type', 'application/json'); response.setBody('{"animal":{"id":2,"name":"bear","eats":"berries, campers, adam seligman","says":"yum yum"}}'); response.setStatusCode(200); return response; } } @isTest private class AnimalLocatorTest{ static testMethod void testLocator() { Test.setMock(HttpCalloutMock.class, new AnimalLocatorMock()); String actualValue = AnimalLocator.getAnimalNameById(2); String expectedValue = '{"animal":{"id":2,"name":"bear","eats":"berries, campers, adam seligman","says":"yum yum"}}'; System.assertEquals(actualValue, expectedValue); } } So, I run the test (also tried run All option), have 100% coverage. If needed I can provide my org credentials for check. Thanks!
Dmitriy JediDmitriy Jedi
It is dev console shows the class extention like .apxc in IDE its .cls please see screenshots
Marek Kosar_Marek Kosar_
I don't see any issue in you code, but check this out->
https://developer.salesforce.com/forums/?id=906F0000000MJiPIAW
Looks like the same problem (with solution), maybe it can help you.
This was selected as the best answer
Dmitriy JediDmitriy Jedi
it strange why I could not query this class, but this helped: * I deleted the file, pasted the same text again, then saved. * Thank you!
Marek Kosar_Marek Kosar_
I'm glad I helped
( please mark this question as solved ;) )
SAHG-SFDCSAHG-SFDC
I am unable to clear this challenge yet, What do I need to write in my Class


public class AnimalLocator { public static String getAnimalNameById(Integer animalId) { String animalName = ''; String endPointUrl = ' https://th-apex-http-callout.herokuapp.com/animals/' + String.valueOf(animalId); Http http = new Http(); HttpRequest request = new HttpRequest(); request.setEndpoint(endPointUrl); request.setMethod('GET'); HttpResponse response = http.send(request); // If the request is successful, parse the JSON response. String result = 'None'; if (response.getStatusCode() == 200) { String jsn = response.getBody(); result = jsn; System.debug(' --------------> ' + jsn); } return result; } } @isTest global class AnimalLocatorMock implements HttpCalloutMock { // Implement this interface method global HTTPResponse respond(HTTPRequest request) { // Create a fake response HttpResponse response = new HttpResponse(); response.setHeader('Content-Type', 'application/json'); response.setBody('{"animal":{"id":2,"name":"bear","eats":"berries, campers, adam seligman","says":"yum yum"}}'); response.setStatusCode(200); return response; } } @isTest private class AnimalLocatorTest{ static testMethod void testLocator() { Test.setMock(HttpCalloutMock.class, new AnimalLocatorMock()); String actualValue = AnimalLocator.getAnimalNameById(2); String expectedValue = '{"animal":{"id":2,"name":"bear","eats":"berries, campers, adam seligman","says":"yum yum"}}'; System.assertEquals(actualValue, expectedValue); } }