public without sharing class PowerBIBaseHandler{ public void test1(){ } }/* public without sharing class PowerBIBaseHandler extends Oly_TriggerHandler { private static Map allTableDesc; private Map newMap; private Map oldMap; private List newList; private List oldList; public PowerBIBaseHandler() { this.newMap = (Map) Trigger.newMap; this.oldMap = (Map) Trigger.oldMap; this.newList = (List) Trigger.new; this.oldList = (List) Trigger.old; } protected override void afterInsert() { upsertPowerBITable(); } protected override void afterUpdate() { upsertPowerBITable(); } protected override void afterUnDelete() { upsertPowerBITable(); } protected override void afterDelete() { deletePowerBITable(); } ////////////////////////// 这里开始是自己的Logic ////////////////////////// private void upsertPowerBITable() { system.debug('=============upsertPowerBITable'); Schema.SObjectType tableType = null; Schema.SObjectField idfs = null; List targeList = new List(); List pbDFList = [SELECT Name, To_Table__c FROM PowerBISyncDefine__c WHERE Delete_Flag__c = false ORDER BY CreatedDate desc]; Map pbDFMap = new Map(); for (PowerBISyncDefine__c pbDF : pbDFList) { pbDFMap.put(pbDF.Name, pbDF.To_Table__c); } boolean hasLookUpId = false; for (SObject nObj : newList) { if (idfs == null) { String tableApiName = nObj.getSObjectType().getDescribe().getName(); // SWAG-BCF4KY 20190524 LHJ 目标询价跳过处理 Start if (tableApiName == 'Opportunity' && nObj.get('RecordTypeId') == '01210000000QekP') { Continue; } // SWAG-BCF4KY 20190524 LHJ 目标询价跳过处理 End if (pbDFMap.containsKey(tableApiName)) { if (allTableDesc == null) { allTableDesc = Schema.getGlobalDescribe(); } // TODO 暂时只对应一个 To_Table__c tableType = allTableDesc.get(pbDFMap.get(tableApiName)); idfs = tableType.getDescribe().fields.getMap().get('PowerBI_Source_Id__c'); hasLookUpId = tableType.getDescribe().fields.getMap().keySet().contains('powerbi_source_lookup_id__c'); } } if (tableType != null) { SObject ups = tableType.newSObject(); targeList.add(ups); ups.put('PowerBI_Source_Id__c', nObj.get('Id')); ups.put('CurrencyIsoCode', nObj.get('CurrencyIsoCode')); if (hasLookUpId) { ups.put('PowerBI_Source_LookUp_Id__c', nObj.get('Id')); } if (nObj.get('Name') != null) { String name80 = ((String) nObj.get('Name')).left(80); ups.put('Name', name80); } // TODO weiwei // 读 fieldset 然后 Loop // TODO 暂时只对应一个 To_Table__c //ups.get(xxxxx) = nObj.get(XXXX) List fieldList = tableType.getDescribe().fields.getMap().values(); //Schema.FieldSet fs = fsMap.get('FieldSet_Api__c'); //List fsmList = fs.getFields(); for (SObjectField fsm : fieldList) { if(!fsm.getDescribe().isCalculated() && fsm.getDescribe().isCustom() && fsm.getDescribe().getName() != 'PowerBI_Source_Id__c' && fsm.getDescribe().getName() != 'PowerBI_Source_LookUp_Id__c') { ups.put(fsm.getDescribe().getName(), nObj.get(fsm.getDescribe().getName())); } } } } if (targeList.size() > 0) { String listType = 'List<' + tableType + '>'; List castRecords = (List)Type.forName(listType).newInstance(); system.debug('test PBI'); castRecords.addAll(targeList); Database.upsert(castRecords, idfs); } } private void deletePowerBITable() { Schema.SObjectType tableType = null; Schema.SObjectField idfs = null; List targeList = new List(); List pbDFList; String tableApiName = oldList[0].getSObjectType().getDescribe().getName(); pbDFList = [SELECT Name, To_Table__c FROM PowerBISyncDefine__c WHERE Name = :tableApiName AND Delete_Flag__c = false ORDER BY CreatedDate desc]; if (pbDFList.size() > 0) { if (allTableDesc == null) { allTableDesc = Schema.getGlobalDescribe(); } // TODO 暂时只对应一个 To_Table__c tableType = allTableDesc.get(pbDFList[0].To_Table__c); idfs = tableType.getDescribe().fields.getMap().get('PowerBI_Source_Id__c'); } Set delIds = new Set(); for (SObject nObj : oldList) { delIds.add(nObj.Id); } String sql = 'SELECT id FROM ' + tableType + ' WHERE PowerBI_Source_Id__c in :delIds'; List delList = Database.query(sql); Database.delete(delList); } } */