You need to sign in to do that
Don't have an account?
Jeevana Priyanka B
I am getting the bellow error message while checking the Apex web service challenge not sure why and even created a new playground but no luck any help is greatly appreciated below is the code.
Error message in Trailhead: "Executing the 'AccountManager' method failed. Either the service isn't configured with the correct urlMapping, is not global, does not have the proper method name or does not return the requested account and all of its contacts."
Apex class:
Thank you in advance.
Apex web service challenge
I am getting the bellow error message while checking the Apex web service challenge not sure why and even created a new playground but no luck any help is greatly appreciated below is the code.
Error message in Trailhead: "Executing the 'AccountManager' method failed. Either the service isn't configured with the correct urlMapping, is not global, does not have the proper method name or does not return the requested account and all of its contacts."
Apex class:
@RestResource(urlMapping='/Accounts/*/Contacts') global with sharing class AccountManager{ @HttpGet global static Account getAccount(){ RestRequest request = RestContext.request; String accId = request.requestURI.substringBetween('/Accounts/','/Contacts'); Account acc = [SELECT Id, Name,(SELECT Id, Name FROM Contacts) FROM Account WHERE Id =: accId LIMIT 1]; return acc; } }Apex test class:
@isTest private class AccountManagerTest{ @isTest static void testGetAccount(){ Id recordId = createTestRecord(); Contact con = new Contact(LastName = 'Con', AccountId = recordId); insert con; Contact con1 = new Contact(LastName = 'Con1', AccountId = recordId); insert con1; RestRequest request = new RestRequest(); request.requestURI = 'https://XXXX.salesforce.com/services/apexrest/Accounts/'+recordId+'/Contacts'; request.httpMethod = 'GET'; restContext.request = request; Account thisAcc = AccountManager.getAccount(); } static Id createTestRecord(){ Account acc = new Account(Name = 'Test Acc'); insert acc; return acc.Id; } }
Thank you in advance.
Please note that Questions about how to pass Trailhead challenges are not on topic, because these challenges are intended to be independent demonstrations of your abilities.
Trailhead Help (https://trailhead.salesforce.com/en/help?support=home)can provide assistance for situations where Trailhead does not appear to be functioning correctly. You can reach out to them if this is the case.
Please close the thread by selecting as best answer so that we can keep our community clean. Thank you