The list of strings should be initialized by an empty list. It was easy.
String[] s = new String[] {};
質問
I am trying to fetch all users of a role and add their email into a string[] i have some syntax.
Error:"common.apex.runtime.impl.ExecutionException: Attempt to de-reference a null object"|0x2f253344
My Code.
String[] s;
for (User a : [Select id,name,email from User where UserRoleId = '00E90000000dffgEAA']) {
s.add(a.email);
}
解決
The list of strings should be initialized by an empty list. It was easy.
String[] s = new String[] {};
他のヒント
I think, it is giving error, because your soql query is not returning any rows. You can do something like this to get rid of errors...
Integer number_of_rows = [Select id,name,email from User where UserRoleId = '00E90000000dffgEAA'];
if(number_of_rows>0)
{
String[] s;
for (User a : [Select id,name,email from User where UserRoleId = '00E90000000dffgEAA']) {
s.add(a.email);
}
}