【发布时间】:2023-03-08 10:26:01
【问题描述】:
我有一个自定义对象同意和偏好,这是孩子的帐户。 要求是根据通道字段限制重复记录。 例如,如果我创建了频道电子邮件的同意,当我尝试使用与频道相同的电子邮件创建第二条记录时,它应该会抛出错误。
以下是我编写的代码,但它只允许我创建一条记录。对于第二条记录,无论频道如何,它都会向我抛出错误:
Trigger code:
set<string> newChannelSet = new set<string>();
set<string> dbChannelSet = new set<string>();
for(PE_ConsentPreferences__c newCon : trigger.new){
newChannelSet.add(newCon.PE_Channel__c);
}
for(PE_ConsentPreferences__c dbcon : [select id, PE_Channel__c from PE_ConsentPreferences__c where PE_Channel__c IN: newChannelSet]){
dbChannelSet.add(dbcon.PE_Channel__c);
}
for(PE_ConsentPreferences__c newConsent : trigger.new){
if(dbChannelSet.contains(newConsent.PE_Channel__c))
newConsent.addError('You are inserting Duplicate record');
}
【问题讨论】:
标签: salesforce salesforce-lightning