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
NehaKS1NehaKS1 

Trigger

Hello,

I have written my logic in one trigger i want to write seperate apex class and call that apex class from trigger.

 

 

Regards,

Neha

puneet28puneet28

Hi Neha,

Suppose this is your class

 

public with sharing class AccountTriggerHandler {
  public static void OnBeforeInsert(List<Account> newAccounts){
        
    }
// some more logic
}

 Your trigger will be:

 

trigger AccountTrigger on Account (after delete, after insert, after undelete, 
after update, before delete, before insert, before update) {
	AccountTriggerHandler.OnBeforeInsert(Trigger.new);
}

 

 

crop1645crop1645

Highly recommended are the various trigger frameworks http://krishhari.wordpress.com/2013/07/22/an-architecture-framework-to-handle-triggers-in-the-force-com-platform/ that the aforementioned post outlines.

 

A bit higher cost effort to set up the first time but they have huge long run pay off for anything but the most trivial systems