代码语言:javascript复制
public static void ignoreValidationRules(List<Sobject> dmlList, String dmlType) {
//跳过验证规则
GlobalSetting__c gs;
GlobalSetting__c oldGS;
List<GlobalSetting__c> gsList = [SELECT Id,
SetupOwnerId,
IgnoreValidation__c
FROM GlobalSetting__c
WHERE SetupOwnerId = :UserInfo.getUserId()];
// 设置当前用户忽略验证规则
if (gsList.size() > 0) {
gs = gsList[0];
} else {
gs = new GlobalSetting__c();
gs.SetupOwnerId = UserInfo.getUserId();
}
oldGS = gs.clone();
gs.IgnoreValidation__c = true;
UPSERT gs;
oldGS.Id = gs.Id;
if (dmlType == 'INSERT') {
insert dmlList;
}
if (dmlType == 'UPDATE') {
update dmlList;
}
if (dmlType == 'DELETE') {
delete dmlList;
}
UPDATE oldGS;
}