You need to sign in to do that
Don't have an account?

Map bring back on 1 of 2 records
In the highlighted query below. The result only returns 1 of 2 records. Any help into how to resolve this. There does exist 2 opportunities in this contact. Thanks in Advance.
public OfferStatusChangeFlowHelper (List <Offer__c> triggerNew) {
if (triggerNew != null)
this.triggerNew = triggerNew;
//get opps and con ids
for (Offer__c offer : triggerNew) {
contactIds.add(offer.Candidate_Name__c);
oppIds.add (offer.opportunity__c);
}
for (Offer__c o:[SELECT Id, Name, Offer_Status__c, Candidate_Name__c FROM Offer__c WHERE Candidate_Name__c IN :contactIds
AND (Offer_Status__c = 'Offer Accepted' OR Offer_Status__c = 'Offer Extended') ]) {
//check map for contact id
if (contactOffersMap.get(o.Candidate_Name__c)==null) {//no entry yet
contactOffersMap.put (o.Candidate_Name__c, new List <Offer__c> {o});
} else {//otherwise get list of opps and add a new one
contactOffersMap.get(o.Candidate_Name__c).add(o);
}
}
for (Opportunity o:[SELECT Id, Name, StageName, Contact__c FROM Opportunity WHERE Id IN :oppIds AND isClosed = false]) {// comment out to test bring back open and closed for first part of step 9.
System.debug('OPPORTUNITY IDS: ' + oppIds);
//for (Opportunity o:[SELECT Id, Name, StageName, Contact__c FROM Opportunity WHERE Id IN :oppIds]) {
//check map for contact id
if (oppMap.get(o.Contact__c)==null) {//no entry yet
oppMap.put (o.Contact__c, new List <Opportunity> {o});
} else {//otherwise get list of opps and add a new one
oppMap.get(o.Contact__c).add(o);
}
}
}
Hi,
In that case, change your selection code to following.
Let us know if this helps!
-Gunish
All Answers
Can you tell us what was the result of this debug statement ?
System.debug('OPPORTUNITY IDS: ' + oppIds);
Regards,
Gunish
|USER_DEBUG|[45]|DEBUG|OPPORTUNITY IDS: {006J000000BCTQbIAP}
I think I figured out the problem.
The basic problem is thet oppIds field gets only a single opportunity Id, where as you are expecting it to contain two.
In this section, you populate oppIds with the values collected in triggerNew collection.
If you add a new item to this collection, one at a time, the oppIDs will get only one OpportunityID.
Following this, further in your code.
You only select, Opportunities which match the values in the oppIds, which will return only one value.
Solution :
If you want to select all the opportunities from your system, simply remove the where clause in your code. which will return both.
Let us know if this helps!
-Gunish
Gunish
Thanks for the suggestion. However, I do not want all opportunities in the system. I want all opportunities for a specific contact.
Hi,
In that case, change your selection code to following.
Let us know if this helps!
-Gunish