使用 SOQL 查询无法获取帐户 Applicant_ID__c

using SOQL Query not able to fetch Account Applicant_ID__c

我在名为 Applicant_ID__c 的帐户中有一个外部 ID。我正在使用数据加载器将数据导入 salesforce Opportunity。下面是我的映射文件内容。

Date\ Cancelled=Date_Cancelled__c
Date\ Denied=Date_Denied__c
Date\ Decisioned=Date_Decisioned__c
App\ Status=Application_Status__c
Date\ Submitted=Application_Submitted__c
Closing\ Date=CloseDate
Application\ Source=Application_Source__c
Application\ Type=Application_Type__c
Application\ Sub-Type=Application_Sub_Type__c
App\ ID=App_ID__c
Property=Property_Name__r\:Property_Code__c
Applicant\ ID=Account\:Applicant_ID__c
Record\ Type\ ID=RecordTypeId

上面的映射现在工作正常,我想要的是从触发器填充机会名称。 下面是我的触发内容

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

for (Opportunity o : Trigger.New){


Account acc = [Select LastName From Account Where Applicant_ID__c =:Account:Applicant_ID__c];

o.Name =acc.LastName;
}  

}

提前致谢。

你查询错了 首先,你不应该在 for 循环中查询

List'<'Opportuniy opplist = new list'<'Opportunity'>'();<Br/>
// Remove the single quotes <br/>
for (Opportunity o : Trigger.New){<Br/>
o.OpportunityApplicentID = o.Account.Applicant_ID__c;<Br/>
o.Name =acc.LastName;<Br/>
opplist.add(o);<Br/>
}
update opplist;

+而不是使用 Applicant_ID__c =:Account:Applicant_ID__c this.。只需使用 Applicant_ID__c =:Account.Applicant_ID__c。不要使用冒号。使用点运算符

如果插入 101 个机会,您创建和排除的答案将会爆炸,但如果您想使用 Applicant_ID__c,您可以在帐户查询中查询它

trigger MapStatusToStageBeforeOpportunintyCreation on Opportunity (before insert, before update) 
{
    Set<ID> acctIDS = new Set<ID>();

    for (Opportunity o : Trigger.new)
    {  
        if(o.AccountId != null)
        {
            acctIDS.add(o.AccountID);
        }                
    } 

    Map<ID, Account> acctMap = new Map<ID, Account>([Select LastName, Applicant_ID__c  From Account Where ID =: acctIDS]); 

    for(Opportunity o : Trigger.new)
    {
        for(ID acctID :acctMap.keySet())
        {
            if(o.AccountID == acctID)
            {
                o.Lastname = acctMap.get(acctID).LastName;          
            }
        }   
    }       
}