public without sharing class AssetMaintainDetailHandler extends Oly_TriggerHandler { private Map newMap; private Map oldMap; private List newList; private List oldList; private Datetime today = System.now(); private Map MAINTYPE_ABBR_MAP = new Map { '断念找回(断念取消)'=> 'DNQX', '断念找回(重新登录)'=>'DNDL', '冻结'=>'DJ', '解冻'=>'JD', '实物报废'=>'BFSW', '废弃(丢失)'=>'BFDS', '废弃(盘亏)'=>'BFPK', '盘盈(数量管理)'=>'PY', '耗材已消耗数'=>'XH' } ; public AssetMaintainDetailHandler() { this.newMap = (Map) Trigger.newMap; this.oldMap = (Map) Trigger.oldMap; this.newList = (List) Trigger.new; this.oldList = (List) Trigger.old; } protected override void beforeInsert() { beforeSetValue(); } protected override void beforeUpdate() { beforeSetValue(); } private void beforeSetValue() { for (AssetMaintainDetail__c nObj : newList) { if(Trigger.isInsert || Trigger.isUpdate){ nObj.Name = 'WHD-' + this.MAINTYPE_ABBR_MAP.get(nObj.MaintainType__c) + this.today.format('-YYYYMM-') + String.valueOf(nObj.OrderNumber__c).leftpad(4, '0'); } } } }