Take the 2-minute tour ×
Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It's 100% free, no registration required.

This question already has an answer here:

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?

share|improve this question

marked as duplicate by Baskaran S, Keith C, Samuel De Rycke, dphil, Jagular Aug 1 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 at 16:25

1 Answer 1

up vote 6 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
FROM User
WHERE Email like :emails];
share|improve this answer
1  
Thanks! Worked perfectly. Didn't realize you could pass a Set of strings to the LIKE operator. –  Matthew Mitchener Aug 1 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 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. –  sfdc_ninja Aug 1 at 16:29
1  
Yeah, I was surprised when I found it worked - I wasn't expecting it to –  Phil Hawthorn Aug 1 at 16:30

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