I have a fundamental question about the how number of SOQL queries calulated in Salesforce.
I have inserted 50 Sample Accounts (Sample0, Sample2 ...Sample49) and trying to perform SOQL query:
List<Account> accs = [SELECT Id FROM Account WHERE Name LIKE 'Sam%'];
logs show the below limits:
Number of SOQL queries: 1 out of 100
Number of query rows: 50 out of 50000
Number of SOSL queries: 0 out of 20
Number of DML statements: 0 out of 150
Number of DML rows: 0 out of 10000
Now, when i try to query and delete accounts:
List<Account> accs = [SELECT Id FROM Account WHERE Name LIKE 'Sam%'];
DELETE accs;
The logs show:
Number of SOQL queries: 2 out of 100
Number of query rows: 50 out of 50000
Number of SOSL queries: 0 out of 20
Number of DML statements: 1 out of 150
Number of DML rows: 50 out of 10000
UPDATE: I am executing the code in Developer console with Execute Anonymous Window. Below is the code:
/*list<Account> iacc = new List<Account>();
for(integer i=0; i<50; i++) {
iacc.add(new Account(Name = 'Sample' + i));
}
insert iacc; */
List<Account> accs = [SELECT Id FROM Account WHERE Name LIKE 'Sam%'];
Delete accs;
I would uncomment 'for loop' and insert statement for re-inserting the accounts later (i would comment SOQL and Delete statment that time)
I was expecting Number of SOQL queries to be still 1, but the limits show it as 2. I guess i am missing something fundamental about the behaviour of SOQL or DELETE. Can you please help me in understanding this?
Thanks in Advance
Accountthat runs eitherbefore deleteorafter delete? – Derek F Nov 24 '16 at 14:17Accountand additionalSOQL querywas being counted from that. Thanks. – Arun Nov 26 '16 at 07:10