我正在尝试创建一个执行以下操作的触发器:
我当前的代码成功完成了第1项,但是当我添加新代码完成第2项时,收到以下错误:
Line: 6, Column: 1
System.DmlException: Insert failed. First exception on row 0; first error:
CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, newAccountCreated: execution of
AfterInsert caused by: System.FinalException: Record is read-only
Trigger.newAccountCreated: line 12, column 1: []
我当前的触发器如下:
trigger newAccountCreated on Account (after insert) {
List<Account> alist = Trigger.New;
for(Account a : alist) {
if (a.RecordTypeId == '012i0000001Iy1H') {
// system.debug(a.Name);
Portal_Content__c p = new Portal_Content__c(Name=a.Name,School_SFDC_ID__c=a.Id);
insert p;
a.Portal_Content_Record__c = p.Id;
update a;
}
}
}
我不明白为什么错误消息指出“记录是只读的”或如何修改此错误。
答案 0 :(得分:1)
您不能在“之后”触发器上更新相同的记录,必须在之前触发器上完成;更改为:
trigger newAccountCreated on Account (before insert) {