• Earl Newcomer 10
  • 0 Points
  • Member since 2018

  • Chatter
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
  • 2
can some one help me to write test class for below code as i am new to salesforce so i don't have much idea related to test class.

public class permissionset {
public void testOCRmethod() {
List < PermissionSetAssignment > permissionSetList = new List < PermissionSetAssignment > ();
Id permissionSetId = [SELECT id FROM permissionSet WHERE Name = 'test1per'].id;
Set < String > profileSet = new Set < String > { 'test1' };
for (User u: [SELECT ID, UserRole.Name, Profile.Name, IsActive FROM User WHERE Profile.Name IN: profileSet AND IsActive = true])

PermissionSetAssignment psa = new PermissionSetAssignment(PermissionSetId = permissionSetId, AssigneeId = u.Id);
upsert permissionSetList;
  • January 02, 2020
  • Like
  • 0
I don't know what I am doing wrong. I've been working on the Animal Locator exercise in trailhead having to do with REST API Callouts and just can not get the result I'm working on to pass the 'Challenge'. My code is 100% tested, and it seems to meet all the criteria, but I keep getting the following message: "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."

Below is my code:

AnimalLocator.apxc (Class)

public class AnimalLocator {
    public static string getAnimalNameById(integer numSubmitted) {
        Http http = new Http();
        HttpRequest request = new HttpRequest();
        request.setEndpoint('https://th-apex-http-callout.herokuapp.com/animals/' + numSubmitted);
        HttpResponse response = http.send(request);
        string replyName = 'None returned';
        if (response.getStatusCode() == 200) {
         replyName = response.getBody();
            return replyName;


private class AnimalLocatorTest {
    @isTest static  void  testGetCallout() {
    // 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 animalname = AnimalLocator.getAnimalNameById(2);
    // Verify that the response received contains fake values       
    String expectedValue = 'Charles H Bones Esquire';
    System.assertEquals(animalname, expectedValue);


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('Charles H Bones Esquire');
        return response;

My code is saved and closed out of and the challenge still fails. Any suggestions would be greatly appreciated. Thanks!