6

Essentially what I want to do is this:

SELECT Id, Email
FROM User
WHERE Email in ('first.last1%','first.last2%')

I am using this in a trigger and would like to come up with a query to match users based on the email prefix. Ideally, I like to avoid using a loop since I'm trying to avoid governor limits.

Anyone have a solution to this?

Matthew Mitchener
  • 1,107
  • 1
  • 12
  • 25

1 Answers1

7

what it looks like you're trying to do is a IN and LIKE. If you drop the wildcarding, your syntax is fine for IN. However, if you do need to do the Like you'll have to change approach.

If you are able to use bind variables, you can do it like this:

Set<String> emails = new Set<String>{'first.last1%','first.last2%'};
List<User> users = [SELECT Id, Email
FROM User
WHERE Email like :emails];
Phil Hawthorn
  • 16,718
  • 3
  • 46
  • 74