문제

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);
    }
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top