You need to sign in to do that
Don't have an account?
cmoynihan
Attempt to de-reference a null object
I am getting an error with the line "mail.setToAddresses" in the following code:
String email = '';
String ownerName = '';
// Check if Owner is a User if (ownerType == 'User'){ User owner = [select Name, Email from User where Id = :c.OwnerId]; email = owner.Email; ownerName = owner.Name; System.debug('Email: ' + email + ', Name: ' + ownerName); String[] toAddresses = new String[]{email}; mail.setToAddresses(toAddresses); ...
The debug message is outputting the Email (and Name) just fine, so I am not sure what the problem is. I use the same syntax is another method and it works just fine, so I'm really not sure what the issue is. Any ideas?
Please provide your complete code as I can suspect "mail." is having some problem. Make sure you are "using Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();". Means you are instantiating the "Messaging.SingleEmailMessage".
Thanks
Ankit Arora
Blog | Facebook | Blog Page
All Answers
Instead of:
String[] toAddresses = new String[]{email};
Try to use:
List<String> toAddresses = new List<String>{email};
Also, make SURE email is not null
Regards,
--Aldo
Please provide your complete code as I can suspect "mail." is having some problem. Make sure you are "using Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();". Means you are instantiating the "Messaging.SingleEmailMessage".
Thanks
Ankit Arora
Blog | Facebook | Blog Page
Like a fool, my mail declaration was somehow after my mail.setToAddress call. Oops. It was fine in my other methods.
Sorry for the idiocy!
You must not have initialized this instance of Messaging.SingleEmailMessage mail
So just initialize it before you refer it
like
cross post
It happens many time with us also cmoynihan. You are not the single one in the race :-)
Thanks
Ankit Arora
Blog | Facebook | Blog Page