【发布时间】:2014-03-11 04:09:05
【问题描述】:
您好,我是 salesforce 的新手,我需要一些帮助来解决 Apex 触发器问题。
我尝试使用机会上的触发器创建合同记录。当 Opportunity SatgeName 更改为“Pending win”时,以下代码将创建一个合同记录。问题是当机会更新时,代码似乎不起作用。请让我知道我哪里出错了。
附上代码。
trigger CreateContract on Opportunity (after insert, before update) {
List<Contract> conttoinsert = new List<Contract>();
for (Opportunity opp : Trigger.new) {
// Create contract record only when the Stage is Updated to "Pending Win"
if (opp.StageName == 'Pending win') {
Contract con = new Contract();
con.Opportunity_Name__c = opp.id;
con.Account = opp.Account;
con.CurrencyIsoCode = opp.CurrencyIsoCode;
conttoinsert.add(con); // For Bulk processing of the Records.
} //end if
} // End of For
// Inserting the New Contract Record.
try {
insert conttoinsert;
} catch (system.Dmlexception e) {
system.debug (e);
}
}
非常感谢任何帮助。
谢谢
【问题讨论】:
标签: triggers salesforce apex