Advanced Apex Patterns: Designing for Scalability & Performance

apexCopy codeList<Account> accountsToUpdate = [SELECT Id, Name FROM Account WHERE ...];
for(Account acc : accountsToUpdate) {acc.Name = 'Updated Account';}update accountsToUpdate;
apexCopy codeglobal class BatchAccountUpdate implements Database.Batchable<SObject> {global Database.QueryLocator start(Database.BatchableContext bc) {return Database.getQueryLocator('SELECT Id FROM Account WHERE ...');}global void execute(Database.BatchableContext bc, List<SObject> scope) {=List<Account> accountsToUpdate = (List<Account>) scope;for(Account acc : accountsToUpdate) {acc.Name = 'Updated via Batch';}update accountsToUpdate;}global void finish(Database.BatchableContext bc) {// Optional code to run after batch completes}}
apexCopy codepublic class AccountService {public static void updateAccountNames(List<Account> accounts) {for(Account acc : accounts) {acc.Name = 'Service Updated';}update accounts;}}

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top