Question

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);
    }
Était-ce utile?

La solution

The list of strings should be initialized by an empty list. It was easy.

String[] s = new String[] {};

Autres conseils

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);
    }
}
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top