public without sharing class PowerBIBaseHandler{
|
public void test1(){
|
}
|
}/*
|
public without sharing class PowerBIBaseHandler extends Oly_TriggerHandler {
|
private static Map<String, Schema.SObjectType> allTableDesc;
|
|
private Map<Id, SObject> newMap;
|
private Map<Id, SObject> oldMap;
|
private List<SObject> newList;
|
private List<SObject> oldList;
|
|
public PowerBIBaseHandler() {
|
this.newMap = (Map<Id, SObject>) Trigger.newMap;
|
this.oldMap = (Map<Id, SObject>) Trigger.oldMap;
|
this.newList = (List<SObject>) Trigger.new;
|
this.oldList = (List<SObject>) 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<SObject> targeList = new List<SObject>();
|
List<PowerBISyncDefine__c> pbDFList = [SELECT Name, To_Table__c
|
FROM PowerBISyncDefine__c
|
WHERE Delete_Flag__c = false
|
ORDER BY CreatedDate desc];
|
Map<String, String> pbDFMap = new Map<String, String>();
|
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<Schema.SObjectField> fieldList = tableType.getDescribe().fields.getMap().values();
|
//Schema.FieldSet fs = fsMap.get('FieldSet_Api__c');
|
//List<FieldSetMember> 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<SObject> castRecords = (List<SObject>)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<SObject> targeList = new List<SObject>();
|
List<PowerBISyncDefine__c> 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<String> delIds = new Set<String>();
|
for (SObject nObj : oldList) {
|
delIds.add(nObj.Id);
|
}
|
String sql = 'SELECT id FROM ' + tableType + ' WHERE PowerBI_Source_Id__c in :delIds';
|
List<SObject> delList = Database.query(sql);
|
Database.delete(delList);
|
}
|
}
|
*/
|