function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Max Prown 9Max Prown 9 

Button to mass update contacts from account

Hi,

I've created a button on the Account object that will update a field on the Account's Contact records that causes a trigger to fire. The code itself works fine when there are only a few contact records to be updated, but obviously in large batches it causes a delay and I wasn wondering if anyone had any tips for bulkifiying this type of solution Here's the code: 
global with sharing class UpdateContactsButton{
    public List<Contact> ConList {get;set;}   
    webService static  String updateactcontacts(ID caseId){
        List<Contact> ListToUpdate = new List<Contact>();
        List<Contact> conlist = [SELECt ID, AccountID, Update_For_Workflow__c From Contact WHERE AccountId = :caseId];
     For(Contact c : Conlist){
            c.Update_For_Workflow__c = 'Selling Agreement Update' ;
            ListToUpdate.add(c);
        }
        If(ListToUpdate.size() > 0){
            update ListToUpdate;
        }
        return null;
    }
    }

Thanks in advance!
Siddharth83JainSiddharth83Jain
Hi Max,

Do you mean bulkifying for account updates and then its contacts subsequently?

Thanks
Siddharth
OSI Consulting
Max Prown 9Max Prown 9
Hi Siddharth,

No this is only meant to update a field on Contacts that will kick off triggers for Contacts. I'm sure there are better ways of achieving this, but I wanted to see if this would provide a stop gap solution while we build out something more robust. Thanks!
Siddharth83JainSiddharth83Jain
And what are you triggers doing on a contact record? Could explain a bit more about where the delay is in large batch. Do you mean that if an account has many contacts than the performance degrades even for a sinngle account update?
Max Prown 9Max Prown 9
They’re querying the Account page to see what products they’re eligible to sell and then they update the Contact fields based on what information they return. And yes, the occurs on single accounts with a many contacts. Thanks! Max Prown Salesforce Administrator Franklin Square Capital Partners 215-220-6345 max.prown@franklinsquare.com
Siddharth83JainSiddharth83Jain
Hi Max,

Was just thinking if we can achieve this via Actions. Can we do that if possible

Thanks
Siddharth
OSI Consulting