I have created two triggers
One for 'Short-Term Strategic Products' & one for 'Long-Term Strategic Products'
I am wondering is there any possibility i can merge these two triggers into one ?or do you think its best to keep them separate
----------Short Term Trigger ------------
trigger ObjectNameCheckProducts on Campaign (before insert, before update) {
// Look up record type id
String recordTypeName = 'Short-Term Strategic Products'; // <-- Change this to your record type name
Map<String,Schema.RecordTypeInfo> rtMapByName = Schema.SObjectType.Campaign.getRecordTypeInfosByName();
Schema.RecordTypeInfo rtInfo = rtMapByName.get(recordTypeName);
id recordTypeId = rtInfo.getRecordTypeId();
for(Campaign o : Trigger.New){
if(o.RecordTypeId == recordTypeId) {
Integer counter = 0;
if(o.Institutional_Products_A_G__c != null)
counter += o.Institutional_Products_A_G__c.split(';').size();
if(o.Institutional_Products_G_Z__c != null)
counter += o.Institutional_Products_G_Z__c.split(';').size();
if(o.Intermediary_Products_A_F__c != null)
counter += o.Intermediary_Products_A_F__c.split(';').size();
if(o.Intermediary_Products_G_L__c != null)
counter += o.Intermediary_Products_G_L__c.split(';').size();
if(o.Intermediary_Products_M_Z__c != null)
counter += o.Intermediary_Products_M_Z__c.split(';').size();
if(counter > 5) o.addError('Max 5 values can be selected from Product lists');
}
}
}
---------long Term Trigger ----------
trigger ObjectNameCheckProducts on Campaign (before insert, before update) {
// Look up record type id
String recordTypeName = 'Long-Term Strategic Products'; // <-- Change this to your record type name
Map<String,Schema.RecordTypeInfo> rtMapByName = Schema.SObjectType.Campaign.getRecordTypeInfosByName();
Schema.RecordTypeInfo rtInfo = rtMapByName.get(recordTypeName);
id recordTypeId = rtInfo.getRecordTypeId();
for(Campaign o : Trigger.New){
if(o.RecordTypeId == recordTypeId) {
Integer counter = 0;
if(o.Institutional_Products_A_G__c != null)
counter += o.Institutional_Products_A_G__c.split(';').size();
if(o.Institutional_Products_G_Z__c != null)
counter += o.Institutional_Products_G_Z__c.split(';').size();
if(o.Intermediary_Products_A_F__c != null)
counter += o.Intermediary_Products_A_F__c.split(';').size();
if(o.Intermediary_Products_G_L__c != null)
counter += o.Intermediary_Products_G_L__c.split(';').size();
if(o.Intermediary_Products_M_Z__c != null)
counter += o.Intermediary_Products_M_Z__c.split(';').size();
if(counter > 10) o.addError('Max 10 values can be selected from Product lists');
}
}
}