+ Start a Discussion
SFDC TortoiseSFDC Tortoise 

Trailhead CHALLENGE. Create an Apex REST service that returns an account and it's contacts.

Hi everyone,

i'm getting the following error after the system checks the challenge:
"Challenge Not yet complete... here's what's wrong: 
There was an unexpected error in your org which is preventing this assessment check from completing: System.QueryException: List has no rows for assignment to SObject"

Apex class

global with sharing class AccountManager {
    global static Account getAccount(){
        RestRequest request = RestContext.request;
        String accountId = request.requestURI.substringBetween('Accounts/','/contacts');
        Account objAccount=[SELECt id, name,(select id, name from Contacts) from Account
                           where id=:accountId limit 1];
        return objAccount;


Test class

private class AccountManagerTest {
    static testMethod void testMethod1(){
        Account objAccount = new Account(Name='Test Account');
        insert objAccount;
        Contact objContact = new Contact(LastName= 'test Contact',
                                        AccountId = objAccount.Id);
        insert objContact;
        Id recordID = objAccount.Id;
        RestRequest request = new RestRequest();
        request.requestURI = 'https://cunning-moose-pmifqd-dev-ed.my.salesforce.com/services/apexrest/Accounts/' +
                    recordId + 'contacts';
        request.httpMethod = 'GET';
        RestContext.request = request;
        Account thisAccount = AccountManager.getAccount();
        System.assert(thisAccount!= null);
        system.assertEquals('Test Account', thisAccount.Name);


Can somebody help me with this?
Thank you,

Best Answer chosen by SFDC Tortoise
VinayVinay (Salesforce Developers) 

Review below links which can help you.


We have separate Trailhead team who can help you with these issues.So,can you please use the below link to reach out to them so that one of the agent will get in touch with you.


Hope above information was helpful.

Please mark as Best Answer so that it can help others in the future.

Vinay Kumar