Code Snippet Slide 20
//For loop to iterate through all the incoming Account records
for(Account a: accounts) {
//THIS FOLLOWING QUERY IS INEFFICIENT AND DOESN'T SCALE
//Since the SOQL Query for related Contacts is within the FOR loop, if this
//trigger is initiated
//with more than 100 records, the trigger will exceed the trigger governor limit
//of maximum 100 SOQL Queries.
*List contacts = [select id, salutation, firstname, lastname, email
from Contact where accountId = :a.Id];
for(Contact c: contacts) {
c.Description=c.salutation + ' '+ c.firstName + ' ' + c.lastname;
//THIS FOLLOWING DML STATEMENT IS INEFFICIENT AND DOESN'T SCALE
//Since the UPDATE DML (data manipulation language) operation is within the FOR loop, if this trigger is
//initiated with more than 150 records, the trigger will exceed the trigger
//governor limit of 150 DML Operations maximum.
*update c;
}
}
Terminer et continuer