【发布时间】:2020-11-06 03:03:50
【问题描述】:
我在 Opportunity 对象上为插入前和更新前创建了一个触发器,通过它我将 Trigger.newMap 变量作为参数发送到我的 apex 类,在该类中我正在检查是否存在特定组合中的记录如果不存在特定的记录模式,则另一个称为记录组合的对象会尝试添加错误。但是当我尝试创建一个机会或更新它时,我得到了以下异常。
OppRecordCombo: execution of BeforeUpdate caused by: System.FinalException: SObject row does not allow errors ()
我的触发器在下面
trigger OppRecordCombo on Opportunity (before insert, before update) {
if((Trigger.isBefore && Trigger.isInsert) || (Trigger.isBefore && Trigger.isUpdate)) {
OppRecordComboClass opp = new OppRecordComboClass();
opp.checkComboValidate(Trigger.newMap);
}
}
我的顶级课程如下
public without sharing class OppRecordComboClass {
//private List<Opportunity> opportunities;
String recordComboString;
String oppComboString;
List<String> recordComboStringList = new List<String>();
public OppRecordComboClass() {
}
public void checkComboValidate(Map<Id, Opportunity> opportunities) {
try {
List<Record_Combination__c> recordcombo = [SELECT Client__r.Name,
Client_SFDC_ID__c,
Agency__r.Name,
Agency_SFDC_ID__c
FROM Record_Combination__c];
for(Record_Combination__c recComb : recordcombo) {
recordComboString = recComb.Client__r.Name + recComb.Client_SFDC_ID__c + recComb.Agency__r.Name + recComb.Agency_SFDC_ID__c;
recordComboStringList.add(recordComboString);
}
List<Opportunity> oppCheckList = [SELECT Id,
Account.Name,
AccountId,
Agency_Name__r.Name,
Agency_Name__c,
Allow_New_Account_Combination__c
FROM Opportunity
WHERE Id in :opportunities.keySet()];
for(Opportunity opp : oppCheckList) {
if(opp.Allow_New_Account_Combination__c == false) {
oppComboString = opp.Account.Name + opp.AccountId + opp.Agency_Name__r.Name + opp.Agency_Name__c;
System.debug('This is the opp combo string akki ' + oppComboString);
if(!recordComboStringList.contains(oppComboString)) {
//Opportunity triggerOpp = opportunities.get(opp.Id);
opportunities.get(opp.Id).addError('This Customer and Agency combination doesn\'t exist in OB. Do you still want to create this Opportunity');
}
}
}
} catch(Exception e) {
System.debug('An exception occured at the line ' + e.getLineNumber() + ' exception is ' + e.getMessage());
}
}
}
谁能告诉我为什么会发生这种情况以及如何纠正?
【问题讨论】:
标签: exception error-handling salesforce