You need to sign in to do that
Don't have an account?
Sue Irvine 16
soql select from list when not in object
Hi all, I have a REST API endpoint set-up to receive a list of Id's (external ID on the Contact) for processing. I would like to be able to return a list of external ID's in this list, that don't exist in our Contacts. Although we currently have less that 50K Contacts, I know it won't be that way for much longer. This is what I'm doing currently:
List<String> badEmplids = new List<String>(); Set<Contact> allContacts = new Set<Contact>([select Cornell_id__c from Contact]); Set<String> allConString = new Set<String>(); for (contact c : allContacts){ allConString.add(c.cornell_id__c); } for (string s : emplidIds){ if (! allConString.contains(s)){ badEmplids.add(s); } }Am I missing something obvious? Ideally I would want to select from the LIST where the external id is not in the Contact.
The problem is your 'badEmplids' list is empty. So there is no value to iterate on for the FOR loop.
What you are saying is not possible because you gotta have a list of external IDs to compare from right?
You can't compare an empty list.
You have to have a list of contaning all the external IDs regardless of it is present in your contacts.
If you don't have that option then what you can do is:
Return the list of external IDs present in your contacts. And configure your API in such way that the logic is not performed for the IDs present in the returned list.
Unfortunately I cannot create a list of all the external ID's in my Contacts as it would exceed the Governor limit of 50K rows in a SOQL query.
But thanks anyway for trying to help!
This code runs when someone uploads a list of external ID's via a CSV file, or from a JSON request. It is likely that someone will have a typo and send one or more invalid external ids. When that happens I'd like to return a list of the invalid entries so they know to correct those.