我的触发器给了我“从Id到SOBJECT的非法转让:用户”错误。
当自定义对象中的字段是特定值时,触发器应该创建新的机会。我想从对象中输入一些字段到机会中。
trigger MDwinning2 on MD_Meeting__c (after update) {
List <Opportunity> oppToInsert = new List <Opportunity> ();
for (MD_Meeting__c m : Trigger.new) {
if (m.SAL__c==True) {
Opportunity o = new Opportunity ();
o.OwnerId = m.Sales_Director__c;
o.Name = m.Name;
o.StageName = 'Generate Opportunity';
o.Market_Developer__c = m.Market_Developer__c;
o.AccountId = m.Account__c;
o.Type = 'Sales - New Business';
o.CloseDate = System.Today()+150;
o.MeetingLookup__c = m.Id;
oppToInsert.add(o);
}//end if
}//end for o
//try {
// insert oppToInsert;
// } catch (system.Dmlexception e) {
// system.debug (e);
// }
}
答案 0 :(得分:1)
更改
o.Owner = m.Sales_Director__c;
o.Account = m.Account__c;
到
o.OwnerId = m.Sales_Director__c;
o.AccountId = m.Account__c;
答案 1 :(得分:0)
我已经写了这个答案以供进一步讨论,因为问题没有解决
trigger MDwinning2 on MD_Meeting__c (after update) {
List <Opportunity> oppToInsert = new List <Opportunity> ();
for (MD_Meeting__c m : Trigger.new) {
if (m.SAL__c == True) {
Opportunity o = new Opportunity ();
o.OwnerId = m.Sales_Director__c;
o.Name = m.Name;
o.StageName = 'Generate Opportunity';
o.Market_Developer__c = m.Market_Developer__c;
o.AccountId = m.Account__c;
o.Type = 'Sales - New Business';
o.CloseDate = System.Today() + 150;
o.MeetingLookup__c = m.Id;
oppToInsert.add(o);
}
}
insert oppToInsert;
}
尝试此代码,如果错误再次出现,请在评论中发布错误消息