-1

我在 Account 中有一个名为申请人_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;
}  

}

提前致谢。

4

3 回答 3

2

如果插入 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;          
            }
        }   
    }       
}
于 2016-08-05T22:42:53.460 回答
1

你查询错了首先,你不应该在 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;
于 2016-08-03T15:32:28.497 回答
-1

+而不是使用 .JustApplicant_ID__c =:Account:Applicant_ID__c this.使用Applicant_ID__c =:Account.Applicant_ID__c.Don't 使用冒号 .Use dot operator

于 2016-08-04T05:41:11.790 回答