You need to sign in to do that
Don't have an account?
Nikita Yadav 17
Dynamic SOQL query with IN clause
Hello,
I am passing List<String> (it contains list of ids) to my dynamic SOQL query from the apex code and I am getting query in debug log as,
SELECT Id, Colour__c, Show_Hide_in_Table__c, OwnerId, Owner.UserRoleId, Owner.Name, StageName, Status__c, LastActivityDate, CreatedDate FROM Opportunity WHERE Id IN ('0065w000025xUyVAAU', '0065w000025xUyZAAU', '0065w000025xUx7AAE', '0065w000025xUw9AAE', '0065w000025xUy5AAE', '0065w000025xUykAAE', '0065w000025xUuLAAU', '0065w000025xUyQAAU', '0065w000025xUvcAAE', '0065w000025xUKfAAM', ...) AND Show_Hide_in_Table__c = 'Show' ORDER BY StageName
So my question is that,
1) What is that ... (three dots) at the end of ids?
Note: I did not add that ... from my apex code
2) Is it necessary to pass : (Colon) when used IN clause in dynamic soql?
Thanx in advance.
I am passing List<String> (it contains list of ids) to my dynamic SOQL query from the apex code and I am getting query in debug log as,
SELECT Id, Colour__c, Show_Hide_in_Table__c, OwnerId, Owner.UserRoleId, Owner.Name, StageName, Status__c, LastActivityDate, CreatedDate FROM Opportunity WHERE Id IN ('0065w000025xUyVAAU', '0065w000025xUyZAAU', '0065w000025xUx7AAE', '0065w000025xUw9AAE', '0065w000025xUy5AAE', '0065w000025xUykAAE', '0065w000025xUuLAAU', '0065w000025xUyQAAU', '0065w000025xUvcAAE', '0065w000025xUKfAAM', ...) AND Show_Hide_in_Table__c = 'Show' ORDER BY StageName
So my question is that,
1) What is that ... (three dots) at the end of ids?
Note: I did not add that ... from my apex code
2) Is it necessary to pass : (Colon) when used IN clause in dynamic soql?
Thanx in advance.
That three dots are because there are more id's in your List<string>.
No, it is necessary when we use IN in soql.
https://developer.salesforce.com/docs/atlas.en-us.soql_sosl.meta/soql_sosl/sforce_api_calls_soql_select_comparisonoperators.htm
-https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/langCon_apex_SOQL_variables.htm
Please mark it as Best Answer if it helps you.
Thanks & Regards
Suraj Tripathi
All Answers
That three dots are because there are more id's in your List<string>.
No, it is necessary when we use IN in soql.
https://developer.salesforce.com/docs/atlas.en-us.soql_sosl.meta/soql_sosl/sforce_api_calls_soql_select_comparisonoperators.htm
-https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/langCon_apex_SOQL_variables.htm
Please mark it as Best Answer if it helps you.
Thanks & Regards
Suraj Tripathi
Thanks for the reply.
But where do I can find those extra ids?
You can refer below link to print all element of a list
https://salesforce.stackexchange.com/questions/51461/how-to-print-all-the-elements-of-a-list
Thanks!
Id xyzID = 'two';
string Success = 'Success';
string today='today';
//string today='Yesterday';
set<id>recId = new set<id>();
recId.add(abcID);
recId.add(xyzID);
system.debug('recId:'+recId);
system.debug('recId_size:'+recId.size());
String numString = String.join(new List<Id>(recId), '\',\'');
system.debug('numString:'+numString);
string soqlDy = 'select id, name,number__c from Account'+ ' where number__c in (\''+ numString +'\')' + ' and Processed_Status__c!= \''+Success+'\''+ ' and CreatedDate='+today ;
system.debug('soqlDy: '+soqlDy);
List<account> accList = new list <Account>();
accList = Database.query(soqlDy);