0

I have a comma separated list that I want to query but it is not working correctly. I am not entirely sure what I am doing wrong. My pAddress is a parm that I am passing in as a Set

 for (String lstEmails : pAddress.split(','))
    {
       System.debug(Logginglevel.DEBUG , 'My Debug lstEmails  :' + lstEmails) ;

        List<String> strEmail =  lstEmails.split(',');

        System.debug(Logginglevel.DEBUG , 'My Debug strEmail  :' + strEmail) ;

    }

    //get the user from the User Object
    User user = [select email, firstName, lastName from User where email IN: pAddress];

The SOQL is not returning any rows. Do I have to format it differently?

1 Answer 1

2

Yes you need to filter on the list.

List<User> users = [SELECT ... FROM User WHERE Email IN :pAddress.split(',')];

You can cache it beforehand if you prefer something more verbose:

List<String> emails = pAddress.split(',');
List<User> users = [SELECT ... FROM User WHERE Email IN :emails];
3
  • I get an error of "Method does not exist or incorrect signature: void split(String) from the type List<String>"
    – Brooke
    May 15, 2018 at 15:14
  • @Brooke In your post you have pAddress as a string on which you call plist(','). If it's a list, you can just merge it in directly.
    – Adrian Larson
    May 15, 2018 at 15:17
  • hmmm, I ended up changing my passed in parm as a list. Then just ran my select statement as: "User user = [select email, firstName, lastName from User where email IN: pAddress". I then get an error of " List has no rows for assignment to SObject" - the list contains [email protected], [email protected]. If I use workbench to query it directly it has records returned.
    – Brooke
    May 15, 2018 at 16:32

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .