You need to sign in to do that
Don't have an account?
Tommy C
Using SOQL to Map Contact IDs to Emails only returns the first Contact from the passed in list
Hi, I'm having some issues with getting the Contact IDs from their emails. I have a list of emails (around 1000 users) that I want to get their Contact IDs for. Using a VLookup table isn't the most efficient because there are over 3 million Contact records to sort through. If there's an easier way, let me know!
I tested the code below and it returns only the first value of the list of emails. When I do the query for [SELECT id, name, email FROM Contact WHERE email IN :emails], it only returns one object. What am I doing wrong?
String users = 'johnny@abc.com, jimmy@abc.com, jonas@abc.com'
List<String> emails = users.split(',');
public static Map<String, id> contactIDFromEmail(List<String> emails){
Map<String, id> cm = new Map<String, id>();
Contact[] c = [SELECT id, name, email FROM Contact WHERE email IN :emails];
for(Contact cont : c){
cm.put(cont.email, cont.id);
}
return cm;
}
I tested the code below and it returns only the first value of the list of emails. When I do the query for [SELECT id, name, email FROM Contact WHERE email IN :emails], it only returns one object. What am I doing wrong?
String users = 'johnny@abc.com, jimmy@abc.com, jonas@abc.com'
List<String> emails = users.split(',');
public static Map<String, id> contactIDFromEmail(List<String> emails){
Map<String, id> cm = new Map<String, id>();
Contact[] c = [SELECT id, name, email FROM Contact WHERE email IN :emails];
for(Contact cont : c){
cm.put(cont.email, cont.id);
}
return cm;
}
Try: The difference is that you will recieve e.g. "jimmy@abc.com", not " jimmy@abc.com"