You need to sign in to do that
Don't have an account?

'System.NullPointerException: Attempt to de-reference a null object' when running a test class for a batch email job
Hi all,
when trying to run my test class, this fails with the error:
This is pointing to the code line in my apex class "String [] toEmailAddress = new String [] {er.ToEmailAddress__c};":
and to one line before the Test.startTest() begins. This is my test class:
when trying to run my test class, this fails with the error:
System.NullPointerException: Attempt to de-reference a null object
This is pointing to the code line in my apex class "String [] toEmailAddress = new String [] {er.ToEmailAddress__c};":
global void sendEmail(){ Messaging.reserveSingleEmailCapacity(2); Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage(); // Strings to hold the email addresses to which you are sending the email. Email_Reminder__c er = Email_Reminder__c.getInstance('List'); String [] toEmailAddress = new String [] {er.ToEmailAddress__c}; String replyToAddress = er.replytoAddress__c; String SenderDisplayName= er.SenderDisplayName__c; ...
and to one line before the Test.startTest() begins. This is my test class:
@isTest public class EmailReminder_Test { static testMethod void testMethod() { insert new Email_Reminder__c(Name =='TestCS', ToEmailAddress__c='test@email.com', replytoAddress__c = 'test@email.com', Subject__c = 'Test Email Reminder', SenderDisplayName__c = 'Test Sender', Body__c = 'This is a test email reminder'); Test.startTest(); EmailReminder sendEmailJob = new EmailReminder(); String sch = '00 30 20 5 2 ? *'; system.schedule('sendEmailJob', sch, sendEmailJob); Test.stopTest(); } }I tried to fix it, but can not handle this til now. Any tips?
Hope this helps you!
Thanks
Varaprasad
@For Support: varaprasad4sfdc@gmail.com
All Answers
please check once following code :
Hope this helps you!
Thanks
Varaprasad
@For Support: varaprasad4sfdc@gmail.com
I think this is because the ToEmailAddress variable is declared as array and my test class is expecting a value in an array, but I can't still handle it.
Hope this helps you!
Thanks
Varaprasad
@For Support: varaprasad4sfdc@gmail.com