自定义对象上的Apex触发器可自动填充帐户和自定义对象的查找字段

对于一般开发人员来说我是新手,因此我试图创建一个触发器来更新自定义对象test2对象上的自定义查找字段Test1__c和account__c。我创建了一个名为test2 o的自定义对象,该对象与“帐户”和“测试1”具有一对一的关系。尝试保存“商机”记录时遇到错误,尽管它在下面提到了正确的引用,但没有填充字段。错误代码下面粘贴了我的代码。“错误:无效数据。 查看以下所有错误消息以更正您的数据。 Apex触发器Populatetest2引起了意外的异常,请与管理员联系:Populatetest2:触发器为字段Repcode更改的数据:数据值太大:(值已隐藏)“

trigger PopulateTest2 on Test1(before insert,before update) {
set<ID> setofTest2 = new set<id>();
set<ID> setofcontactuser     = new set<id>();
for (Test1 CA : trigger.new){
    if(CA.Test2_Name__c != null){
        setofTest2.add(CA.Test2_Name__c);}
    if(CA.contactuser__c!=null){
        setofcontactuser.add(CA.contactuser__c); }   }       
    List<Test2__c> Test2List  = [Select contactuser__c from Test2__c where id in: setofTest2];
    List<account>  accList = [Select Name from account where id in: setofcontactuser];    
 for(Integer i = 0; i < Trigger.new.size(); i++){
    if (Trigger.new[i].Test2__c != null) {
       Trigger.new[i].Test2__c = Test2List[i].ID;            
    }
    if (Trigger.new[i].contactuser__c != null) {
       Trigger.new[i].contactuser__c  = accList[i].ID;            
    }
}
}
masycq 回答:自定义对象上的Apex触发器可自动填充帐户和自定义对象的查找字段

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/3152274.html

大家都在问