You need to sign in to do that
Don't have an account?
Miguel Gonzalez 4
Adding 'Handler' class to currently working Trigger on After Insert action
I have a working Apex trigger that is set to fire whenever someone tries to edit an existing case's FTP Actions field. Here is the coding as it stands now:
trigger UpdateFTPCases on FTP_Action__c (after insert) {
List<Case> updtCases = new List<Case>();
for(FTP_Action__c f : Trigger.new){
//After Insert trigger area
if (f.FTP_to_Case__c != null && f.Action_Date_Time__c != null) {
updtCases.add(new Case(
Id = f.FTP_to_Case__c,
Last_Upload__c = f.Action_Date_Time__c));
}
}
if (!updtCases.isEmpty()) {
update updtCases;
}
}
This trigger has been tested and unit tested and works fine. My manager would like to see if we can add in a Handler class and adjust the code as necessary. This is just us playing around with Triggers and there are no plans to use these in production. Being written for Sandbox use only.
trigger UpdateFTPCases on FTP_Action__c (after insert) {
List<Case> updtCases = new List<Case>();
for(FTP_Action__c f : Trigger.new){
//After Insert trigger area
if (f.FTP_to_Case__c != null && f.Action_Date_Time__c != null) {
updtCases.add(new Case(
Id = f.FTP_to_Case__c,
Last_Upload__c = f.Action_Date_Time__c));
}
}
if (!updtCases.isEmpty()) {
update updtCases;
}
}
This trigger has been tested and unit tested and works fine. My manager would like to see if we can add in a Handler class and adjust the code as necessary. This is just us playing around with Triggers and there are no plans to use these in production. Being written for Sandbox use only.
There's also a cookbook for this as well: http://developer.force.com/cookbook/recipe/trigger-pattern-for-tidy-streamlined-bulkified-triggers
Hope this helps!
My favorite trigger framework (along with a few other MVPs) is Kevin O'Hara's framework. https://github.com/kevinohara80/sfdc-trigger-framework. Like others, it forces you to write your trigger logic in separate Apex classes. Additionally, the framework has built in hooks for recursion checks, running on before and after update, etc. Check it out.