0

I have a collection of set and and i am doing dynamic binding at run time.

Set<String> accountset=new Set<String>{'a','b'};

I am executing query like

List< account>=[select group__c from account where group__c in :accountset];

How can i confirm that at run time it is doing

List< account>=[select group__c from account where group__c in('a','b')];

is there any way i can print like system.debug(final query);

  • C'mon now SOQL != SQL. That's almost as bad as confusing Java and Javascript. – Adrian Larson Apr 27 '18 at 21:40
  • 1
    C'mon now, Adrian, David could very well be a new sf dev. :) – Sebastian Kessel Apr 27 '18 at 23:11
1

You could add the following lines to your code which should provide the confirmation that you're looking for.

//First, before you run the query, add the following statement:
integer q1= limits.getQueries();
If(!isEmpty(q1)) system.debug('queries before = ' + q1);

//run your query
List< account>=[select group__c from account where group__c in :accountset];
integer q2= limits.getQueries();

If(!isEmpty(q1) && !isEmpty(q2)) system.debug('query ran if = 1 ==> ' + (q2-q1) ); 
  • Thanks @crmprogdev. Wouldn't it will only confirm that query is running. Is there any way i can print actual query in debug logs.Thanks – David Mycka Apr 27 '18 at 21:25
  • That's correct. It only confirms that your query ran as written. You can of course run system.debug for all the variables that compose your query if you feel that's necessary. You can also test to see if you returned results using list.isEmpty(). – crmprogdev Apr 28 '18 at 11:27
4

No. Even if you try to read the debug logs, you'll simply see something like:

select group__c from account where group in :tmpvar1

Unfortunately, the only way to see what the final query would have been would be to build your own string, but even that wouldn't be precisely the same behavior.

0

By default the logging does not provide the input and output detail.

I recommend using JSON.serializePretty to get full detail of the inputs to the query and the outputs:

System.debug('accountset=\n' + JSON.serializePretty(accountset));

List<account> accounts =[select group__c from account where group__c in :accountset];

System.debug('accounts=\n' + JSON.serializePretty(accounts));

during development. This outputs all the data rather than the first few elements that just concatenating in a string does. But best to remove this when the code is working well as this sort of debugging generates a lot of data and uses a lot of the CPU limit.

  • Thanks Keith, I don't think its working – David Mycka May 2 '18 at 20:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.