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

Question About Bulk Operation Of Data
Hi all,
Just want to ask if I add a for loop just inside the trigger bracket will the trigger has the ability to handle bulk operation of Data? ie.
trigger ContactRelationshipTrigger on Contact (before insert, before update) {
for(Contact CON : Trigger.New){
...
}
}
If not, how to realize it? Thanks.
Yes, going around a for loop is the beginning of bulk-ificiation
It needs to be coupled however with things like consolidating SOQL queries over aggregated criteria data, rather than a soql query for every record in your for loop. Ditto for updates.
eg
List <Id> accIds = new List<Id>{};
for(Contact con : Trigger.New){
accIds.add(con.AccountId); // aggregate account ids in a list, to query for all accounts at once in one soql query later
}
Accounts[] accs = [Select Id, Name from Account where Id IN:accIds];