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
madhavi mishramadhavi mishra 

Trigger Handler

Hi ,
I am new in devlopment side. Somebody help me to write Trigger but I do not how to write Trigger Handler. Please help..

My Trigger: 
 trigger populateParentAccount on account(after insert) {
      Account[] updates = new Account[0];
      Set<Id> accountIds = new Set<Id>();
      for(Lead record: [SELECT ConvertedAccountId, Agency_Account__c FROM Lead WHERE ConvertedAccountId = :Trigger.new ORDER BY ConvertedDate DESC]) {
        // Avoid multiple leads with same account 
        if(!accountIds.add(record.ConvertedAccountId)) { 
          updates.add(new Account(Id=record.ConvertedAccountId, ParentId=record.Agency_Account__c));
        }
      }
      update updates;
    }

 
Prafull G.Prafull G.
Have a look at this documentation page where you will find all key points about trigger development.
https://developer.salesforce.com/page/Apex_Code_Best_Practices
Andrew GAndrew G
Hi Madhavi

Here is an example of Trigger with Handler I have done before for a Case Trigger.  Review to have some direction on how to create the Handler etc.

https://developer.salesforce.com/forums/ForumsMain?id=9062I000000IK8dQAG

Regards
Andrew