简体   繁体   English

Apex触发器以更新查找字段(联系人)

[英]Apex Trigger to Update Lookup Field (Contact)

Need some advise on how to populate a lookup field (contact) via apex trigger 需要一些关于如何通过顶点触发器填充查找字段(联系人)的建议

  1. I've created a lookup field called Contact__c on Idea object. 我已经在Idea对象上创建了一个名为Contact__c的查找字段。
  2. I would like to populate the Contact__c with the createdby User if it was originated from the web (CreatedBy.Contact.Account.Name == "Web Ideas") and leave it empty for internal idea creation. 我想用用户创建的Contact__c(如果它源自网络(CreatedBy.Contact.Account.Name ==“ Web Ideas”)填充),并将其留空以用于内部想法创建。
  3. I have read up and created the following trigger and was able to save and run. 我已经阅读并创建了以下触发器,并且能够保存并运行它。 However, upon saving the idea record, i am getting an error : UpdateContactonComplaints: data changed by trigger for field Contact: id value of incorrect type: 005N0000000l9iMIAQ 但是,保存想法记录后,我遇到了一个错误:UpdateContactonComplaints:触发器的字段Contact:ID值类型不正确的数据已更改:005N0000000l9iMIAQ

trigger UpdateContactonComplaints on Idea (before insert, before Update) { 触发Idea上的UpdateContactonComplaints(在插入之前,更新之前){

list<id> oid = new list<id>();
for(Idea o: trigger.new){                   
    oid.add(o.id);
        }
map<id, Idea> ExtendU = new map<id, Idea>(
    [select CreatedbyID from Idea where id in: oid]);

for(Idea o: trigger.new){
    o.Contact__c = ExtendU.get(o.id).CreatedbyID;
}

} }

In the Trigger, the user id(id of the User who created the idea) is assigned to Contact custom lookup field). 在触发器中,将用户ID(创建想法的用户的ID)分配给联系人自定义查找字段)。

So, it throws an error, data changed by trigger for field Contact: id value of incorrect type: 因此,将引发错误,触发器的字段Contact:ID值类型不正确的数据已更改:

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Apex触发器从自定义对象更新联系人 - Apex Trigger to Update Contact from Custom Object 是否需要Apex类或仅触发器即可更新Salesforce中的查找字段? - Do I need an Apex Class or just a Trigger in order to update a lookup field in Salesforce? 每次创建新案例时,APEX 触发器都会使用案例编号更新联系人字段 - APEX Trigger to Update Contact Field with Case Number every time new Case is Created Apex 触发器(插入前):在创建新潜在客户记录期间使用自定义查找字段中的值更新公司名称 - Apex Trigger (before insert): Update the Company Name, During the Creation of a New Lead Record, with the Value in a Custom Lookup Field 使用Apex触发器(Salesforce)自动将字段复制到查找字段 - Automatically Copy A Field To A Lookup Field With Apex Trigger (Salesforce) 触发以根据机会更新自定义查找字段 - Trigger to update a custom lookup field on opportunity Salesforce Apex触发器 - 如何检查更新触发器中是否包含字段? - Salesforce Apex Triggers - How to check if field is included in update trigger? 在salesforce中更新相应的联系人字段时,触发更新帐户提交 - trigger to Update account filed, when a corresponding contact field is updated in salesforce APEX触发以从“自定义”对象中的字段更新“标准”对象中的字段 - APEX Trigger to update field in Standard object from field located in Custom object Salesforce触发器以填充查找字段 - Salesforce Trigger to populate a lookup field
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM