0

我正在尝试从机会联系人角色中获取一个人的姓名……这可能还是完全不符合要求?这是我已经拥有的代码。我意识到从contactRole 获取contactID 并没有返回名称......我需要在那里获得名称吗?

trigger add_primary_advisor on Opportunity(before update) {

for(Opportunity o: Trigger.new){

     if (!Trigger.oldMap.get(o.id).IsClosed) {
       OpportunityContactRole contactRole =
            [select ContactID from OpportunityContactRole where IsPrimary = true and OpportunityId = :o.id];
       if (contactRole != null) {
         o.Primary_Advisor__c=contactRole.contactID;
       }
     }
   }    
}
4

1 回答 1

0
 //If Contact.Name doesn't works try fetching Contact.FirstName, Contact.LastName 
   List<String> names = new List<String>();
    for(OpportunityContactRole contactRole =
        [select Contact.Name from OpportunityContactRole where IsPrimary = true and OpportunityId = :o.id]){
      names.add(contactRole .Contact.name)
  }
于 2013-07-10T15:35:06.230 回答