You need to sign in to do that
Don't have an account?
problem with SOQL Bind
Need help with the following SOQL statement:
List<Contact> existingCons = [select ID, FirstName, LastName, Email, Department, Unit__c, StartDate__c, EndDate__c, Title, Phone from Contact where userID__c != null AND userID__c IN :idToUser.keySet()];
Here's the deal. This query isn't returning any records when it should be returning one. I know that it should be returning one because I know there is currently only one record because I am using the interface to trigger this code. I have used system.debug to confirm this. So the following
system.debug(idToUser.keySet());
returns the expected value, which is just an SF ID for the User object.
when I query directly for the id...like this
List<Contact> existingCons = [select ID, FirstName, LastName, Email, Department, Unit__c, StartDate__c, EndDate__c, Title, Phone from Contact where userID__c != null AND userID__c ='005Q0000000W6xbIAC'];
The record is found as expected. That ID is the exact Id that is returned by the system.debug.
Does anybody see what I'm doing wrong?
Thanks!
FALSE ALARM! I figured it out
Here is the solution:
Here is the one that was causing problems:
The difference between the one that works and the one that doesn't work is the position of the SOQL statement. In the one that works I put the SOQL statement beneath the for Loop that populates the idToUser map. I should have warned that I'm beginner!
Thanks for the help, though!
All Answers
The queries are identical, the only thing therefore that can be suspected is the keySet(). Puzzling.
What is the Map declared as ? Map<Id,...?
Is this part of a trigger or a cotrolller - maybe the context is making a difference of some sort?
This is part of a trigger, and the map is declared like so
and userID__c is a Text field set to 18 charaters.
Here is another variation of the query that I thought might help me debug, but doesn't maybe it will help somebody else...
I tried this to see if had something to do with the 'IN' operator or because it was iterating through a list, but this query works fine...it finds the record.
FALSE ALARM! I figured it out
Here is the solution:
Here is the one that was causing problems:
The difference between the one that works and the one that doesn't work is the position of the SOQL statement. In the one that works I put the SOQL statement beneath the for Loop that populates the idToUser map. I should have warned that I'm beginner!
Thanks for the help, though!