Skip to content

xgeek-net/sfdc-apex-trigger-framework

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 

Repository files navigation

SFDC Apex Trigger Framework

@see https://www.xgeek.net/salesforce/a-simple-salesforce-trigger-framework/

Deploy to Salesforce

Well,this is another Salesforce Trigger framework but more simple.

Usage

###AccountTriggerHandler.cls

//This is a sample code for AccountTriggerHandler
public class AccountTriggerHandler extends TriggerHandler{

    public override void beforeInsert(){
    	System.debug( 'AccountTriggerHandler beforeInsert Start' );

    	System.debug( 'Trigger.isExecuting : ' 	+ isExecuting );
    	System.debug( 'Trigger.isInsert : ' 	+ isInsert );
    	System.debug( 'Trigger.isUpdate : ' 	+ isUpdate );
    	System.debug( 'Trigger.isDelete : ' 	+ isDelete );
    	System.debug( 'Trigger.isBefore : ' 	+ isBefore );
    	System.debug( 'Trigger.isAfter : ' 	+ isAfter );
    	System.debug( 'Trigger.isUndelete : ' 	+ isUndelete );
    	System.debug( 'Trigger.new : ' 		+ newList );
    	System.debug( 'Trigger.newMap : ' 	+ newMap );
    	System.debug( 'Trigger.old : ' 		+ oldList );
    	System.debug( 'Trigger.oldMap : ' 	+ oldMap );
    	System.debug( 'Trigger.size : ' 	+ size );

    	System.debug('AccountTriggerHandler beforeInsert End');
    }

    public override void afterInsert(){
    	System.debug('AccountTriggerHandler afterInsert Start');
    }

    public override void beforeUpdate(){
    	System.debug('AccountTriggerHandler beforeUpdate Start');
    }

    public override void afterUpdate(){
    	System.debug('AccountTriggerHandler afterUpdate Start');
    }

    public override void beforeDelete(){
    	System.debug('AccountTriggerHandler beforeDelete Start');
    }

    public override void afterDelete(){
    	System.debug('AccountTriggerHandler afterDelete Start');
    }

    public override void afterUndelete(){
    	System.debug('AccountTriggerHandler afterUndelete Start');
    }
    
}

###AccountTrigger.trigger ####In normal case.

trigger AccountTrigger on Account (before delete, before insert, before update, 
                                    after delete, after insert, after update,after Undelete) {
    TriggerHandlerManager handlerManager = new TriggerHandlerManager();
    handlerManager.add( new AccountTriggerHandler() );
    handlerManager.run();
}

####Other cases Stop and resume sObject Trigger in APEX code

TriggerHandlerManager.stop( 'CustomObject__c' );
TriggerHandlerManager.resume( 'CustomObject__c' );

Stop and resume a TriggerHandler in APEX code

TriggerHandlerManager.stop( 'AccountTriggerHandler' );
TriggerHandlerManager.resume( 'AccountTriggerHandler' );

About

A Salesforce Trigger framework but more simple

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages