Let’s say I have a following piece of code:
Set<Id> accountIds = new Set<Id>(); for(Contact c : [SELECT Name FROM Contact WHERE AccountId IN :accountIds]){ System.debug(c); }
The
accountIds
set is obviously empty in the example above, but will my Apex code consume 1 SOQL query?
Answer
Yes, even though the Set<Id> accountIds
is empty, 1 SOQL query will be executed and will be counted against the 100 SOQL queries limit.
On a similar note, the code below won’t be counted as 1 DML statement:
List<Account> accounts = new List<Account>();
update accounts;
Attribution
Source : Link , Question Author : smukov , Answer Author : smukov