You need to sign in to do that
Don't have an account?
Lukesh Karmore
I receive continuous error
in apex web service I receive continuous error
Challenge not yet complete in trailhead playground 5
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.
my code is--
@RestResource(urlMapping='/Accounts/*/contacts')
global with sharing class AccountManager {
@HttpGet
global static Account getAccount() {
RestRequest req = RestContext.request;
String accId = req.requestURI.substringBetween('Accounts/', '/contacts');
system.debug(accId);
Account acc = [SELECT Id, Name, (SELECT Id, Name FROM Contacts) FROM Account WHERE Id = :accId];
return acc;
}
}
test class---
@IsTest
private class AccountManagerTest {
@isTest static void testGetContactByaccountId() {
Id recordId = createTestRecord();
// Set up a test request
RestRequest request = new RestRequest();
request.requestUri =
'https://empathetic-panda-ususw6-dev-ed.lightning.force.com/services/apexrest/Accounts/' + recordId + '/contacts';
request.httpMethod = 'GET';
RestContext.request = request;
// Call the method to test
Account thisAccount = AccountManager.getAccount();
// Verify results
System.assert(thisAccount != null);
System.assertEquals('Test record', thisAccount.Name);
}
// Helper method
static Id createTestRecord() {
// Create test record
Account accountTest = new Account(
Name ='Test record');
insert accountTest;
Contact contactTest =new contact(
FirstName='bada',
LastName='Boom',
AccountId=accountTest.id);
insert contactTest;
return accountTest.Id;
}
}
please can any one pss me the challenge ..
thank you
Challenge not yet complete in trailhead playground 5
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.
my code is--
@RestResource(urlMapping='/Accounts/*/contacts')
global with sharing class AccountManager {
@HttpGet
global static Account getAccount() {
RestRequest req = RestContext.request;
String accId = req.requestURI.substringBetween('Accounts/', '/contacts');
system.debug(accId);
Account acc = [SELECT Id, Name, (SELECT Id, Name FROM Contacts) FROM Account WHERE Id = :accId];
return acc;
}
}
test class---
@IsTest
private class AccountManagerTest {
@isTest static void testGetContactByaccountId() {
Id recordId = createTestRecord();
// Set up a test request
RestRequest request = new RestRequest();
request.requestUri =
'https://empathetic-panda-ususw6-dev-ed.lightning.force.com/services/apexrest/Accounts/' + recordId + '/contacts';
request.httpMethod = 'GET';
RestContext.request = request;
// Call the method to test
Account thisAccount = AccountManager.getAccount();
// Verify results
System.assert(thisAccount != null);
System.assertEquals('Test record', thisAccount.Name);
}
// Helper method
static Id createTestRecord() {
// Create test record
Account accountTest = new Account(
Name ='Test record');
insert accountTest;
Contact contactTest =new contact(
FirstName='bada',
LastName='Boom',
AccountId=accountTest.id);
insert contactTest;
return accountTest.Id;
}
}
please can any one pss me the challenge ..
thank you
For all the Trailhead issues or Guidance please report it here,
https://trailhead.salesforce.com/en/help?support=home
https://trailhead.salesforce.com/help
So that our trailhead support engineers will look into it and get back to you.
For further reference check this too,
https://trailblazers.salesforce.com/answers?id=9063A000000pKy2QAE
https://developer.salesforce.com/forums/?id=906F0000000MIzFIAW
Let me know if it helps you and close your query by marking it as solved so that it can help others in the future.
Regards,
Salesforce Support.