【问题标题】:APEX Trigger wont save - Error MessageAPEX 触发器无法保存 - 错误消息
【发布时间】:2016-04-21 11:32:59
【问题描述】:

我有这个 APEX 触发器,我收到了这个错误,但不确定为什么“错误:编译错误:需要一个左尖括号,在第 13 行第 10 列找到'oppcntctrle'”

trigger updatecontactrolecount on Opportunity (before insert, before update)
{

Boolean isPrimary;
Integer iCount;
Map<String, Opportunity> oppty_con = new Map<String, Opportunity>();//check        if the contact role is needed and add it to the oppty_con map
for (Integer i = 0; i < Trigger.new.size(); i++) 
{
oppty_con.put(Trigger.new[i].id,
Trigger.new[i]); 
}
isPrimary = False; 
for (List oppcntctrle :[select OpportunityId from OpportunityContactRole where (OpportunityContactRole.IsPrimary = True and  OpportunityContactRole.OpportunityId in :oppty_con.keySet())])
{
if (oppcntctrle .Size() >0)
{
isPrimary = True; 
}
}
iCount = 0;
for (List oppcntctrle2 : [select OpportunityId from OpportunityContactRole where (OpportunityContactRole.OpportunityId in :oppty_con.keySet())])//Query for Contact Roles

{ 
if (oppcntctrle2 .Size()>0) 
{
iCount= oppcntctrle2 .Size(); 
}
}
for (Opportunity Oppty : system.trigger.new) //Check if roles exist in the map or contact role isn't required 
{
Oppty.Number_of_Contacts_Roles_Assigned__c = iCount;
Oppty.Primary_Contact_Assigned__c =isPrimary; 
}
}

【问题讨论】:

    标签: salesforce apex apex-trigger


    【解决方案1】:

    代替

    for (List oppcntctrle :[select OpportunityId from OpportunityContactRole where (OpportunityContactRole.IsPrimary = True and  OpportunityContactRole.OpportunityId in :oppty_con.keySet())])
    

    应该是

    List<OpportunityContactRole> oppcntctrle = [select OpportunityId from OpportunityContactRole where (OpportunityContactRole.IsPrimary = True and  OpportunityContactRole.OpportunityId in :oppty_con.keySet())];
    

    for (List oppcntctrle2 : [select OpportunityId from OpportunityContactRole where (OpportunityContactRole.OpportunityId in :oppty_con.keySet())])//Query for Contact Roles
    

    应该改为

    List<OpportunityContactRole> oppcntctrle2 = [select OpportunityId from OpportunityContactRole where (OpportunityContactRole.OpportunityId in :oppty_con.keySet())];//Query for Contact Roles
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-10-01
      • 2016-10-26
      • 1970-01-01
      • 2012-11-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多