2013-10-24 43 views
1

我想从所有“计费”联系人角色ID返回字段,这是一个商机记录可能有。Bulkify交叉对象SOQL查询

我希望在我的机会触发一个地图,有机会标识和相关联系人的角色ID列表(即地图>)

我可以从trigger.new循环创建映射键,但不能落得似乎找到了从我的SOQL查询中插入联系人角色ID列表的方法。

List<OpportunityContactRole> contactRoleList 
= new List<OpportunityContactRole>([Select Id 
            From OpportunityContactRole 
            Where Role = 'Billing' 
             And OpportunityId in :listOfTriggerOppIds 
            ]); 

我可以把代码的其余部分,如果需要,但看到因为它没有实际的工作,我想这可能混淆的东西。

+0

请添加您的代码 –

回答

0

不知道我是否理解你的问题,但你的意思是:?

Map<id,list<id>> mapOptyBillings = new Map<id,list<id>>(); //map of opportunityID, list<opportunityContactRole IDs 

List<OpportunityContactRole> contactRoleList 
= new List<OpportunityContactRole>([Select Id, OpportunityId 
            From OpportunityContactRole 
            Where Role = 'Billing' 
             And OpportunityId in :listOfTriggerOppIds 
            ]); 
//also query OpportunityId so that you can match 

//iterate your result 
for(OpportunityContactRole optyCR:contactRoleLis){ 
    //see if our map already has a list for the opportunity of this opportunityContactrole, 
    //if this is not the case, add it with a blank list 
    if(! mapOptyBillings.containsKey(optyCR.OpportunityId)mapOptyBillings.put(optyCR.OpportunityId, new List<id>(); 
    mapOptyBillings.put(optyCR.OpportunityId,optyCR.id); 
}