ApexSensei

Drills Security & deployment

Measure governor headroom

Governor limits cap what one transaction can use, such as 100 SOQL queries.

Your task

Measure how many SOQL queries the loop costs, then load the same Profiles with one query and measure that too.

List<Profile> picked = [SELECT Id FROM Profile ORDER BY Name LIMIT 3];
Set<Id> profileIds = new Map<Id, Profile>(picked).keySet();

Integer loopStart;
List<String> loopNames = new List<String>();
for (Profile item : picked) {
    Profile row = [SELECT Name FROM Profile WHERE Id = :item.Id];
    loopNames.add(row.Name);
}

List<String> bulkNames = new List<String>();
Integer loopCost = -1;
Integer bulkCost = -1;
System.debug('Loop cost: ' + loopCost);
System.debug('Bulk cost: ' + bulkCost);

Requirements

  1. Reads the query counter should be present
  2. Uses one IN query should be present
  3. Measures bulk cost from Limits should be present
  4. Measures the loop should be printed as Loop cost: 3
  5. Measures the bulk query should be printed as Bulk cost: 1
  6. Finds the same Profiles should be printed as Same names: true
  7. Counts five queries in all should be printed as Total queries: 5

Sign in to open this drill