You need to sign in to do that
Don't have an account?
kumarcrm 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;
}
}
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;
}
}
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!!
try to change your class URI name for contacts to Contacts.
try with below.
If this helps, Please mark it as best answer.
thanks!!
sames issue i am faceing
Create a brand new Playground, copy/paste the code and then check the challange.
If this helps, please mark it as best answer.
Thanks!!