Search code examples
apex-codesoql

Get All users with UserRoleID


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);
    }

Solution

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

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