You can create static or instance methods on your Apex Class. In your trigger you can then have code that calls these classes. This is very similar to the way method calling works in other languages. Here is a simple example.
Apex Class:
public class SampleClass
{
public void SampleMethod(List<Account> listAccount, Map<Id, Account> mapAccount){
}
}
Apex Trigger:
trigger SampleAccount on Account (before insert)
{
for(Account a : trigger.New){
SampleClass obj = new SampleClass(Trigger.New, Trigger.NewMap);
obj.SampleMethod();
}
}
public class CreateAccountController{
//Prpoerties
public Account acc {get;set;}
//Constructor
public CreateAccountController(){
//Instances
acc = new Account();
}
//Save Method
public PageReference SaveMethod(){
Insert acc;
return null;
}
}
This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish.AcceptReject