You need to sign in to do that
Don't have an account?
Wes Reed 27
Trigger that Auto Updates field on parent when child record is updated
Is there a way to automatically update the Callable_Contacts__c field on the Account object when a related Contact is updated?
trigger CallableContacts on Account (before insert, before update) { for(Account acc : Trigger.new) { //Search for related Contacts List<Contact> callableContacts = [SELECT Id, Phone, Account.Name FROM Contact WHERE Account.Id = :acc.Id]; System.debug('Callable contacts found: ' + callableContacts.size()); //For each contact, check whether the Phone Number field is filled in and increment the callable contacts field on Account Integer count = 0; if(!callableContacts.isEmpty()) { for(Contact con : callableContacts) { if(con.Phone != null) { count = count + 1; acc.Callable_Contacts__c = count; } } } } }
David Zhu 🔥
This trigger is on Account object. You may need to create a AFTER trigger on Contact object.