You need to sign in to do that
Don't have an account?

SOQL In Operator not working as expected
Hello. I am trying to use the invocableMethod annotation to pass some ids from a flow to the method that will return a list of custom Sobjects.
For some reason the soql is only finding the first record, and I don't see why. Posted here is the class and a debug log. Thanks for any help!!

For some reason the soql is only finding the first record, and I don't see why. Posted here is the class and a debug log. Thanks for any help!!
public with sharing class getCampaigns_Flow { @invocableMethod public static list<list<Campaign__c>> getCampaigns(list<string> campaignIds) { system.debug('campaignIds: '+campaignIds); list<list<Campaign__c>> varCamps = new list<list<Campaign__c>>(); List<string> varIds = campaignIds[0].split(';'); system.debug('varIds: '+varIds); list<Campaign__c> camps = [select Id, Target_Audience__c, Geographic_Targeting__c, Search_Keywords__c, Creative_Versions_Per_Flight__c from Campaign__c where Id In :varIds]; varCamps.add(camps); system.debug('camps: '+camps); system.debug('varCamps: '+varCamps); return varCamps; } }
Try this :
Hope this helps you!
If my answer helps resolve your query, please mark it as the 'Best Answer' & upvote it to benefit others.
Salesforce Freelance Consultant/Developer/Administrator/Trainer
@For Salesforce Project Support: varaprasad4sfdc@gmail.com
Salesforce latest interview questions and training videos :
https://www.youtube.com/channel/UCOcam_Hb4KjeBdYJlJWV_ZA?sub_confirmation=1
Thanks,
V Varaprasad
Email: varaprasad4sfdc@gmail.com
You can directly pass the argument "campaignIds" in to the SOQL Query.
I have set debugs for the list on line 5,6&7. see the logs how data is coming.
In the above code, on line 9 you are just passing only one record Id by using index "campaignIds[0]" to the list "varIds". That is why your query is returning one record.
But now you can above code and query as you are expecting.
Mark it is a best answer. If it helps you.
I have been looking a little further at the docs on the comparison operators. https://developer.salesforce.com/docs/atlas.en-us.soql_sosl.meta/soql_sosl/sforce_api_calls_soql_select_comparisonoperators.htm
It says 'The values for IN must be in parentheses. String values must be surrounded by single quotes.' I noticed in my debugs that the values were not in quotes. So, I tried the following code to put get them in quotes before using them in the code. I also tried the = operator because it seems to be interchangeable with IN but that doesn't work either. And you will notice I'm using a set, but I have also tried that set as a list. None of this works. Actually, it's worse now because the query finds no results with the quotes.
And this works exactly as expected.
So there must be something wrong with how I am constructing the various bind variables that I have tried.
So, then I tried just creating a string to bind instead of a list. And, I get the following 'IN operator must be bound to an iterable variable'. I understand the error. This seems to be a dead end. Just want to point it out to save anybody else the time of trying it.
Here is that code.
The string that is comming from visual flow should be split by semicolon with a whitespace