You need to sign in to do that
Don't have an account?

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?
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?
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
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.
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.
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.