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

Populating the triger data at the beginning of the handler class


I have trigger in below pattern

One Account trigger
- Calls Trigger handler

Account Triger handler
- makes distinhuish betwen before ,after, insert, updae
- have each fucntion , which call class to execute actions/functions

I want to improve the trigger to get the data at the beinning of the handler class and execute the trigge logic by using the map 
in other owrds, SOQL to get the user and Account data in beginning and store in map. and use the map in the rest of the account handler.

where i could start from, please 


    trigger AccountTrigger on Account(before insert, before update)  
        AccountTriggerHandler handler = new  AccountTriggerHandler();
        handler.updateUser(;  // Call method for update account field.


Trigger Handler Class:

    public class AccountTriggerHandler

//TO DO: contruct the account list and pass this map to othr functions

           public void updateUser(List<Account> accList)
                  Set<Id> masterIds = new Set<Id>();
                  for(Account accObj : accList)
                    if(accObj.Master__c != null)
                    Map<Id,Master__c> masterMap = new Map<Id,Master__c>([Select Id, test_user1__c from Master__c where Id IN : masterIds]);
                  for(Account acct : accList)
                       Master__c masterObj = masterMap.get(acct.Master__c);
                        if(acct.test_user1__c == null)
                           acct.test_user1__c = masterObj.test_user1__c;

AnkaiahAnkaiah (Salesforce Developers) 
Hi Sandrine,

Please refer the below link will help you to proceed further.

i am looking for populating queries in beginning but not best practices