function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Priya SubbaramanPriya Subbaraman 

Developer 1 exam question

Hi,

Can someone explain this question to me? The web site where I found this question states the answer as 0 orders will be successfully loaded, but I didn't understand why.   Is it because the governor limit on the number of SELECTs is 100?

Thank you.
Priya

List<Account> customers = new List<Account>();
For (Order__c o: trigger.new)
{
Account a = [SELECT Id, Is_Customer__c FROM Account WHERE Id = :o.Customer__c];
a.Is_Customer__c = true;
customers.add(a);
}
Database.update(customers, false);
The developer tests the code using Apex Data Loader and successfully loads 10 Orders. Then, the developer loads 150 Orders.
How many Orders are successfully loaded when the developer attempts to load the 150 Orders?
Best Answer chosen by Priya Subbaraman
Waqar Hussain SFWaqar Hussain SF
Total number of SOQL queries issued = 100

See Salesforce limitations 
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_gov_limits.htm

IN the above soql query is used in for loop. So for each record one soql query will be consued. When 100 records are processed, the total number of SOQL queries limit will be hit and further record will be be update. As in the code database.update with false paratmeter method is using, which indicates partial success. 

Hope this make sense. 

All Answers

Steven NsubugaSteven Nsubuga
 Is it because the governor limit on the number of SELECTs is 100? Yes!!
The SOQL query is inside a loop, loading 150 orders means the query would have to run 150 times yet the governor limit is 100 SOQL queries per transaction.
Waqar Hussain SFWaqar Hussain SF
Total number of SOQL queries issued = 100

See Salesforce limitations 
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_gov_limits.htm

IN the above soql query is used in for loop. So for each record one soql query will be consued. When 100 records are processed, the total number of SOQL queries limit will be hit and further record will be be update. As in the code database.update with false paratmeter method is using, which indicates partial success. 

Hope this make sense. 
This was selected as the best answer
Priya SubbaramanPriya Subbaraman
Thank you. Priya
Priya SubbaramanPriya Subbaraman
That explains it. Thank you. Priya
Waqar Hussain SFWaqar Hussain SF
Please don't forget to mark Best Answer for the most helpful answer.
Rahul Garg SFDRahul Garg SFD
Answer of this will be 0.

According to question, when you load 150 Orders , you would be hitting 150 SOQL queries, but the limt of SOQL queries is only 100, so you will get an error  "System.LimitException:Too many SOQL queries"

Try the following code in anonymous window::

List<Account> customers = new List<Account>();
For (Integer i=0; i< 150;i++){
    Account a = [SELECT Id, name FROM Account limit 1];
    a.name = 'Acc' + i;
    customers.add(a);
}
Database.update(customers, false);

Sorry to say, but please don't mark the correct answer blindly as lots of salesforce developers highly depend on this site.