You need to sign in to do that
Don't have an account?
Kris Webster
Apex Class Functionality
Hey guys, I have written this class to extend my Trigger Handler Base code, and have gotten the code to pass without any errors, however it is not doing exactly what I want it to do.
BREAKDOWN
I have a object called Project (pse__Proj__c) that has a lookup field on it called campaign (Campaign__c). I also have another object called Expense Reports (pse__Expense_Report__c) that also has the same lookup field on it, buit with a different API name (Campaign_Expense__c). Basically what I need the code to do is that when a new expense report record is created I need the value that is found in the Campaign (Campaign__c) field (on the project object) to fill the campaign object on the expense report object with the same value.
Here is the code I have, but it is not filling the field on the expense report object with the campaign. PLEASE HELP !
BREAKDOWN
I have a object called Project (pse__Proj__c) that has a lookup field on it called campaign (Campaign__c). I also have another object called Expense Reports (pse__Expense_Report__c) that also has the same lookup field on it, buit with a different API name (Campaign_Expense__c). Basically what I need the code to do is that when a new expense report record is created I need the value that is found in the Campaign (Campaign__c) field (on the project object) to fill the campaign object on the expense report object with the same value.
Here is the code I have, but it is not filling the field on the expense report object with the campaign. PLEASE HELP !
/************************************************************************************************************************ // Name ExpenseReportHandler // Description Standard trigger handler for ExpenseReportHandler // Revisions 2018-Nov-20 kris.webster@levvel.io Initial version ***********************************************************************************************************************/ public without sharing class ExpenseReportHandler extends TriggerHandlerBase { // Local catches for bulkified data private map<id, pse__Proj__c> projMap = new map<id, pse__Proj__c>(); // key = record id /************************************************************************************************************ // Name bulkBefore // Description Standard implementation of the TriggerHandler.bulkBefore() interface method. *************************************************************************************************************/ public override void bulkBefore() { if (trigger.isInsert || trigger.isUpdate) { set<id> projIds = new set<id>(); for (SObject so : trigger.new) { pse__Expense_Report__c er = (pse__Expense_Report__c)so; if (er.Campaign_Expense__c != null) { projIds.add(er.Campaign_Expense__c); } } // Fetch accounts and their default attributes projMap = new map<Id, pse__Proj__c>( [SELECT Id, Campaign__c FROM pse__Proj__c WHERE Id IN :projIds]); } } /************************************************************************************************************ // Name beforeInsert // Description Standard implementation of the TriggerHandler.afterInsert() interface method. *************************************************************************************************************/ public override void beforeInsert(SObject so) { pse__Expense_Report__c newER = (pse__Expense_Report__c)so; setcamp(newER); } /************************************************************************************************************ // Name beforeUpdate // Description Standard implementation of the TriggerHandler.afterUpdate() interface method. *************************************************************************************************************/ public override void beforeUpdate(SObject oldSo, SObject so) { pse__Expense_Report__c newER = (pse__Expense_Report__c)so; setcamp(newER); } /************************************************************************************************************ // Name queueDeliveryManagerSync // Description Helper method to sync delivery manger to parent opty *************************************************************************************************************/ private void setcamp (pse__Expense_Report__c exprep) { // If the expense reports's campaign is blank, we fill it with the projects campaign if (exprep.Campaign_Expense__c == null && projMap.containsKey(exprep.pse__Project__c)) { exprep.Campaign_Expense__c = projMap.get(exprep.pse__Project__c).Campaign__c; } } }