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
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

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

}

Test class

@isTest
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) 
Hi,

Review below links which can help you.

https://developer.salesforce.com/forums/?id=9060G000000MPHzQAO
https://success.salesforce.com/answers?id=9063A000000eOQZQA2
https://salesforce.stackexchange.com/questions/144749/apex-rest-services-challenge-unclear-on-return-format

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.

Support:https://trailhead.salesforce.com/help

Hope above information was helpful.

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

Thanks,
Vinay Kumar