Hi Realist,Always create on trigger one every object and create multiple method on apex class to create the sequenPlease check below blog for sample code :-http://amitsalesforce.blogspot.in/2015/06/trigger-best-practices-sample-trigger.htmlCreate one Trigger "AccountTrigger" trigger AccountTrigger on Account( after insert, after update, before insert, before update)
{
AccountTriggerHandler handler = new AccountTriggerHandler(Trigger.isExecuting, Trigger.size);
if( Trigger.isInsert )
{
if(Trigger.isBefore)
{
handler.OnBeforeInsert(trigger.New);
}
else
{
handler.OnAfterInsert(trigger.New);
}
}
else if ( Trigger.isUpdate )
{
if(Trigger.isBefore)
{
handler.OnBeforeUpdate(trigger.New ,trigger.Old,Trigger.NewMap,Trigger.OldMap);
}
else
{
handler.OnAfterUpdate(trigger.New ,trigger.Old,Trigger.NewMap,Trigger.OldMap);
}
}
}
Create one Trigger Handler Class
Create one Trigger Action Classpublic with sharing class AccountTriggerHandler
{
private boolean m_isExecuting = false;
private integer BatchSize = 0;
public static boolean IsFromBachJob ;
public static boolean isFromUploadAPI=false;
public AccountTriggerHandler(boolean isExecuting, integer size)
{
m_isExecuting = isExecuting;
BatchSize = size;
}
public void OnBeforeInsert(List<Account> newAccount)
{
system.debug('Account Trigger On Before Insert');
}
public void OnAfterInsert(List<Account> newAccount)
{
system.debug('Account Trigger On After Insert');
}
public void OnAfterUpdate( List<Account> newAccount, List<Account> oldAccount, Map<ID, Account> newAccountMap , Map<ID, Account> oldAccountMap )
{
system.debug('Account Trigger On After Update ');
AccountActions.updateContact (newAccount);
}
public void OnBeforeUpdate( List<Account> newAccount, List<Account> oldAccount, Map<ID, Account> newAccountMap , Map<ID, Account> oldAccountMap )
{
system.debug('Account Trigger On Before Update ');
}
@future
public static void OnAfterUpdateAsync(Set<ID> newAccountIDs)
{
}
public boolean IsTriggerContext
{
get{ return m_isExecuting;}
}
public boolean IsVisualforcePageContext
{
get{ return !IsTriggerContext;}
}
public boolean IsWebServiceContext
{
get{ return !IsTriggerContext;}
}
public boolean IsExecuteAnonymousContext
{
get{ return !IsTriggerContext;}
}
}
Please add all method in Action Class.Please mark this as solution if this will help you.ThanksAmit Chaudharypublic without sharing class AccountActions
{
public static void updateContact ( List<Account> newAccount)
{
// Add your logic here
}
}
1 respuesta