Any help or ideas are appreciated. ThanksSet<ID> ContactIds = new Set<ID>();
for (Opportunity rec: workingOpps)
{
if(rec.Contact__c != null)
{
ContactIds.add(rec.Contact__c);
}
}
Map<ID, CampaignMember> CampaignMember = new Map<id, CampaignMember>(
[select
id, CampaignId from CampaignMember where ContactId in: ContactIds]);
for (Opportunity opp : workingOpps)
{
//Check if the map is empty
Boolean empty = CampaignMember.isEmpty();
if(empty)
{
continue;
}
//check if the campaign id exit in the job.
//CampaignMember memberID = CampaignMember.get(????????????);
//opp.Campaign = CampaignMember.Campaign.id;
}
Hi Semira , Try with below code !!
Set<ID> ContactIds = new Set<ID>();
Map<id, CampaignMember> CampaignMember = new Map<id, CampaignMember>();
for (Opportunity rec: workingOpps)
{
if(rec.Contact__c != null)
{
ContactIds.add(rec.Contact__c);
}
}
for(CampaignMember camp:[select
id, CampaignId,ContactId from CampaignMember where ContactId in: ContactIds]){
CampaignMemberMap.put(camp.ContactId,camp);
}
for (Opportunity opp : workingOpps)
{
if(!CampaignMemberMap.isEmpty() && CampaignMemberMap.get(opp.Contact__c) != null){
opp.Campaign = CampaignMemberMap.get(opp.Contact__c).CampaignId;
}
}
Let me know if it helps!!
ThanksManoj