【发布时间】:2012-01-30 04:59:34
【问题描述】:
我需要防止输入重复的名称。需要使用触发器来施加此限制。我想知道如何限制 DML 操作的发生。不确定 .addError 在批量代码中的用法。
Set<string> Seta= new Set<string>();
for(oj__c o:trigger.new)
{
Seta.add(c.name);
}
List<oj__c> listoj= new List<oj__c>();
listoj=[select id from oj__c where name in :Seta]
if listoj.size()>0
trigger.new.adderror('Cannot have duplicate name');// i know this line is wrong. How can i stop the DML statement from excuting?
【问题讨论】:
标签: salesforce apex-code