You need to sign in to do that
Don't have an account?
CloudGeek
Apex REST Callouts - Challenge Not Yet Complete : Make Sure the method Exists with the Name
Challenge Not yet complete... here's what's wrong:
Executing the 'getAnimalNameById' method on 'AnimalLocator' failed. Make sure the method exists with the name 'getAnimalNameById', is public and static, accepts an Integer and returns a String.
My Class Code is here :
And the TEST Class is as below:
Test Mock Class is as below:
When I queried the ApexClass Object, I could see all 3-classes
Am I missing something or what should I do to succesfully validate this Unit ?
Executing the 'getAnimalNameById' method on 'AnimalLocator' failed. Make sure the method exists with the name 'getAnimalNameById', is public and static, accepts an Integer and returns a String.
My Class Code is here :
global class AnimalLocator { public static String getAnimalNameById(Integer num) { Http http = new Http(); HttpRequest request = new HttpRequest(); request.setEndpoint('https://th-apex-http-callout.herokuapp.com/animals/:'+num); request.setMethod('GET'); HttpResponse response = http.send(request); String answer='VenMal'; // If the request is successful, parse the JSON response. if (response.getStatusCode() == 200) { System.debug('response.getBody() ========'+response.getBody()); answer = 'NEW ANIMAL'; } return answer; } }
And the TEST Class is as below:
@isTest global class AnimalLocatorTest { static testMethod void testCallOut() { // Set mock callout class Test.setMock(HttpCalloutMock.class, new AnimalLocatorMock()); // This causes a fake response to be sent // from the class that implements HttpCalloutMock. string response = AnimalLocator.getAnimalNameById(1); // Verify that the response received contains fake values System.debug('response === '+response); } }
Test Mock Class is as below:
@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":0,"name":"VenMal","eats":"MeaTT","says":"ThanKYoU"}}'); response.setStatusCode(200); return response; } }
When I queried the ApexClass Object, I could see all 3-classes
Am I missing something or what should I do to succesfully validate this Unit ?
Your logic seems not correct and that is why it is giving this error.
Try this:
Read these posts for more:
https://developer.salesforce.com/forums/?id=906F0000000MJXvIAO
https://developer.salesforce.com/forums/?id=906F0000000MLlfIAG
Thanks
Shashikant
All Answers
Your logic seems not correct and that is why it is giving this error.
Try this:
Read these posts for more:
https://developer.salesforce.com/forums/?id=906F0000000MJXvIAO
https://developer.salesforce.com/forums/?id=906F0000000MLlfIAG
Thanks
Shashikant
Thanks a ton for your help!
Any pointers on what is OAuth/ authentication in SFDC how should I start with implmenting auth in SFDC?
This should help you : https://developer.salesforce.com/trailhead/en/mobile_sdk_introduction/mobilesdk_intro_security
Thanks
Shashikant