Every time one of my records which has a Trigger is changed, I'll need to check whether the record's RecordTypeId is listed in a Custom Setting, before calling any other methods from the Trigger.
trigger WE_MasterOppTrigger on Opportunity (
before Insert, after Insert,
before Update, after Update,
before Delete, after Delete){
RecordTypeChecker checker =
new RecordTypeChecker(Trigger.newMap);
checker.validateRecordTypes();
//retrieve validated Opps & process with below classes
if(validatedOpps.size() > 0{
if(Trigger.isBefore){
if(Trigger.isInsert){
//class logic
}
}
//etc
}
So I've created a Class to manage the record type checks & ideally that Class would be able to receive inputs from Triggers with the same structure, for different objects.
public RecordTypeChecker(
Map<Id,Opportunity> newTriggerOpps,
Map<Id,MPM4_BASE__Milestone1_Project__c> newTriggerProjs
){
newOpps = newTriggerOpps;
newProjs = newTriggerProjs;
}
But when I try to create the above constructor which can receive inputs either from Opportunity's Trigger.newMaps or Project's and call the Method from my Opportunity trigger, it causes the error
Constructor not defined: [RecordTypeChecker].(Map
<Id,Opportunity>
)
When I comment out the Projects sections of the constructor, there are no errors -
public RecordTypeChecker(
Map<Id,Opportunity> newTriggerOpps
//Map<Id,MPM4_BASE__Milestone1_Project__c> newTriggerProjs
){
newOpps = newTriggerOpps;
//newProjs = newTriggerProjs;
}
So I guess that the map for the Projects which is not receiving an input is causing the issue.
Will I have to create one of these Classes per object (& Before / After map)?