We have a existing salesforce implementation, we have most of the logic in triggers and trigger handlers. We are still using classic and no mobile or other UI. But still we are planning to implement apex common library for SOC
1. Is there any other better pattern to refactor domain classes that are huge (1000 lines of code )?
We have huge amount of logic in trigger handlers, once we refactored this in selector, domain, service and uow. We still have large amount of code in domain classes. We wrote some helper classes with public methods. .
eg. we have 30 field validations and 20 field defaults and the field defaults. Related object updates etc.
2. Apply Defaults - OnBeforeUpdate event
We have default fields onbeforeupdate event too, for this I extended the domain base class with this method, I know this is not upgrade safe. Is there a better option ? or should I just use onBeforeUpdate method ?
public virtual void onApplyDefaults(Map existingRecords) { }
3. Use custom Setting to Turn trigger on and off as needed
We have custom setting to to turn on and off triggers. for now it seems we need to write extra line of code in the trigger. is there any other better option for this ?
public trigger testtrigger(allevents){
if(customsetting){
domainclass.getTriggerEvent(YourDomain.class).disableAll();
return;
}
call domainclass here
}