You need to sign in to do that
Don't have an account?
Varsha D 9
on This Statement ....request.params.get('id') i m getting system.NullPointerException: Attempt to de-reference a null object
@HttpGet
global static void sendMail(){
RestRequest request = RestContext.request;
String accountId = request.params.get('id');//error
system.debug(accountId);
Account objAccount = [SELECT Id,Name,(SELECT Id,Name FROM Contacts) FROM Account WHERE Id = :accountId LIMIT 1];
// global static void sendMail(){
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
String[] toAddresses = new String[]{'varsha.rcr37@gmail.com'};
mail.setToAddresses(toAddresses);
//Contact con = [SELECT id, firstname FROM Contact LIMIT 1];
EmailTemplate et = [SELECT id FROM EmailTemplate WHERE developerName = 'gmail_salesforce'];
mail.setTargetObjectId(objAccount.id);
mail.setTemplateId(et.id);
Messaging.sendEmail(new Messaging.SingleEmailMessage[] {mail});
}
}
global static void sendMail(){
RestRequest request = RestContext.request;
String accountId = request.params.get('id');//error
system.debug(accountId);
Account objAccount = [SELECT Id,Name,(SELECT Id,Name FROM Contacts) FROM Account WHERE Id = :accountId LIMIT 1];
// global static void sendMail(){
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
String[] toAddresses = new String[]{'varsha.rcr37@gmail.com'};
mail.setToAddresses(toAddresses);
//Contact con = [SELECT id, firstname FROM Contact LIMIT 1];
EmailTemplate et = [SELECT id FROM EmailTemplate WHERE developerName = 'gmail_salesforce'];
mail.setTargetObjectId(objAccount.id);
mail.setTemplateId(et.id);
Messaging.sendEmail(new Messaging.SingleEmailMessage[] {mail});
}
}
Can you double-check the id your supplying from workbench or Postman is not ID or Id? It's basically case-sensitive.
How to avoid such error?
Even before grabbing a value from Map of Params, Transform all KeySet in lowercase in new Map and then grab value from this new Map by using Key.
Also, make sure to add null check-in to your web service.
Thanks,
Ashish Singh.
you have to set your id before exacuting it.from following way you can set it. try it and let me know if your problam is resolved.
avobe answer is only for this question.
Thank you
may i know how are you setting it i mean the acc.id in rest request
are you testing it from test class?
if yes, then simply you have to apply following way. let me know if it helps you.
Thank you