I have a set of Ids for Opportunities which have a specific record type and a new owner. They're in a set so that I can check that the Ids are not included in a list later in the code, using
reassignedOpps.contains(o2.Id) == false
I now need to fetch the complete Opportunity records so that I can populate a string of Opportunity field values.
But I get the following error for line
for(Opportunity oNewOwner : reassignedOpps){
Loop variable must be of type Id
How can I fetch the complete Opportunity records from the reassignedOpps set so that I can use their field values?
trigger OpportunityTargetUpdate on Opportunity (after update) {
Set<Id> reassignedOpps = new Set<Id>();
for(Opportunity o1: oppIds){
Opportunity oldOpp = Trigger.OldMap.get(o1.Id);
if(oldOpp != null
&&
oldOpp.OwnerId != o1.OwnerId)
{
reassignedOpps.add(o1.Id);
}
}
if(reassignedOpps.isEmpty() == true){
System.debug('no Opportunities had new owners');
}
Set<String> identifiers = new Set<String>();
// ERROR HERE
for(Opportunity oNewOwner : reassignedOpps){
identifiers.add(oNewOwner.Identifier__c);
}
List<Opportunity> updatedOpps = new List<Opportunity>();
for(Opportunity o2 : oppIds){
//check whether Close Date month or year has changed but not the owner
Opportunity oldOpp1 = Trigger.OldMap.get(o2.Id);
if(oldOpp1 != null
&&
// ! cannot use contains to check List only Set
reassignedOpps.contains(o2.Id) == false
&&
(oldOpp1.CloseDate.month() != o2.CloseDate.month()
|| // OR
oldOpp1.CloseDate.year() != o2.CloseDate.year()
)){
updatedOpps.add(o2);
}
}
if(updatedOpps.isEmpty() == true){
System.debug('no Opportunities had new close dates');
}
== true
expressions above,if (bool == true)
is always the same isif (bool)
.