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
kumarcrm bingikumarcrm bingi 

I am to finised the super badges but i got an issue on System.NullPointerException: Attempt to de-reference a null object

Apex class Rest API

System.NullPointerException: Attempt to de-reference a null object

@RestResource(urlMapping='/Accounts/*/contacts')
global class AccountManager {
@HttpGet
global static Account getAccount() {
RestRequest request = RestContext.request;
String accId =                request.requestURI.substringBetween('Accounts/','/contacts');
/* Here the issue i am getting System.NullPointerException: Attempt to de-reference a null object */
 Account acc = [SELECT Id, Name, (SELECT Id, Name FROM Contacts) FROM Account WHERE Id = :accId];
return acc;

}


 
AnkaiahAnkaiah (Salesforce Developers) 
Hi Kumar,

Refer the below link have solution for your challange.
https://github.com/Mulodo-Salesforce-Training/trailhead-salesforce-challenge/blob/master/WebServices.md

If this helps, please mark it as best answer.

thanks!!
AnkaiahAnkaiah (Salesforce Developers) 
Hi Kumar,

try to change your class URI name for contacts to Contacts.

try with below.
 
@RestResource(urlMapping='/Accounts/*/Contacts')
global class AccountManager {
@HttpGet
global static Account getAccount() {
RestRequest request = RestContext.request;
String accId =                request.requestURI.substringBetween('Accounts/','/Contacts');
/* Here the issue i am getting System.NullPointerException: Attempt to de-reference a null object */
 Account acc = [SELECT Id, Name, (SELECT Id, Name FROM Contacts) FROM Account WHERE Id = :accId];
return acc;
} 
}
If this helps, Please mark it as best answer.

thanks!!
 
kumarcrm bingikumarcrm bingi
User-added image
sames issue i am faceing
 
AnkaiahAnkaiah (Salesforce Developers) 
Hi Kumar,

 Create a brand new Playground, copy/paste the code and then check the challange.

If this helps, please mark it as best answer.

Thanks!!