Put your hands together

Now that we know about triggers and classes, it's time to revisit our business requirement again and complete the process to synchronize the phone field on contacts with accounts. We'll start by taking our outer class shell and inserting our updateContactPhones() method from Chapter 3, More and Later, as shown:

public with sharing class accountMethods { public static void updateContactPhones( List<Account> priorVersions, List<Account> updatedVersions ){ Set<Id> modifiedAccounts_Ids = new Set<Id>(); for ( Integer i=0;i<updatedVersions.size();i++ ){ if ( updatedVersions[i].Phone != priorVersions[i].Phone ){ modifiedAccounts_Ids.add(updatedVersions[i].Id); } } if ( modifiedAccounts_Ids.size() > 0 ){ List<Contact> contactQuery ...

Get Learning Apex Programming now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.