Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

This question already has an answer here:

Essentially what I want to do is this:

SELECT Id, Email
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?

share|improve this question

marked as duplicate by Baskaran S, Keith C, Samuel De Rycke, dphil, Jagular Aug 1 '14 at 18:03

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

What are you trying to do exactly? Governor limits can be avoided by using proper techniques – EricSSH Aug 1 '14 at 16:25
up vote 7 down vote accepted

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
WHERE Email like :emails];
share|improve this answer
Thanks! Worked perfectly. Didn't realize you could pass a Set of strings to the LIKE operator. – Matthew Mitchener Aug 1 '14 at 16:25
Me neither until I tried it the other day, must parse it out to OR's I guess – Phil Hawthorn Aug 1 '14 at 16:26
I was actually writing up an answer where it took a set and looped through and constructed a soql string using OR's when I saw this answer. Good to know, was unaware of this functionality. thanks. – Chris Duncombe Aug 1 '14 at 16:29
Yeah, I was surprised when I found it worked - I wasn't expecting it to – Phil Hawthorn Aug 1 '14 at 16:30

Not the answer you're looking for? Browse other questions tagged or ask your own question.