You need to sign in to do that
Don't have an account?
SivaG
Urgent ***Need help on logic related to Map handling in trigger ***
Hi,
I have an Opportunity after update trigger. The opportunity should contain only the equipments listed in the Equipment list(Custom setting). If any Opp equipment is not present in Custom setting list then I wanted that to be removed from a Map. I am creating a map of Equipment name(Key) and Opp(Value) but that is creating a problem as we have common equipments between opps.
Trigger code -
Equipmap = PNC_Equipment_List__c.getAll(); //Custom setting data into a map
for(Equipment__c e : [SELECT Id,Name,Opportunity__c FROM Equipment__c WHERE Opportunity__c in :OppOwnerIdMap.keySet()]){
EqpOppMap.put(e.Name,e.Opportunity__c);
}
for(String str : EqpOppMap.keySet()){
if(Equipmap.containsKey(str)){
System.debug('Equip Present ' + str + '-' + EqpOppMap.get(str));
}
else{
System.debug('**** Equip remove Opp Id :' + EqpOppMap.get(str));
OppOwnerIdMap.remove(EqpOppMap.get(str));
}
}
Problem with the code -
If multiple Opps have same equipment, since am storing it in a map with key as Equipment name only few opporunities are getting stored in that map. This is causing some problem as am misssing out on some opportunities.
Ex - I have 4 opps and 3 opps have same equipments(EqupA,EqupB) which are not present in the Equipment list(Custom setting). so I want them to be removed from further processing. so I need a map/list of Opps after removal.
In this case I want only OppC in the final map/list as this EqupC is present in Equipment list(Custom setting)
Before Filter - (How can I handle this in code)
EqupA,OppA
EqupB,OppA
EqupA,OppB
EqupB,OppB
EqupC,OppC
EqupA,OppD
EqupB,OppD
After Filter -
Equpc,Oppc
Please help!
Thanks
Kumar
I have an Opportunity after update trigger. The opportunity should contain only the equipments listed in the Equipment list(Custom setting). If any Opp equipment is not present in Custom setting list then I wanted that to be removed from a Map. I am creating a map of Equipment name(Key) and Opp(Value) but that is creating a problem as we have common equipments between opps.
Trigger code -
Equipmap = PNC_Equipment_List__c.getAll(); //Custom setting data into a map
for(Equipment__c e : [SELECT Id,Name,Opportunity__c FROM Equipment__c WHERE Opportunity__c in :OppOwnerIdMap.keySet()]){
EqpOppMap.put(e.Name,e.Opportunity__c);
}
for(String str : EqpOppMap.keySet()){
if(Equipmap.containsKey(str)){
System.debug('Equip Present ' + str + '-' + EqpOppMap.get(str));
}
else{
System.debug('**** Equip remove Opp Id :' + EqpOppMap.get(str));
OppOwnerIdMap.remove(EqpOppMap.get(str));
}
}
Problem with the code -
If multiple Opps have same equipment, since am storing it in a map with key as Equipment name only few opporunities are getting stored in that map. This is causing some problem as am misssing out on some opportunities.
Ex - I have 4 opps and 3 opps have same equipments(EqupA,EqupB) which are not present in the Equipment list(Custom setting). so I want them to be removed from further processing. so I need a map/list of Opps after removal.
In this case I want only OppC in the final map/list as this EqupC is present in Equipment list(Custom setting)
Before Filter - (How can I handle this in code)
EqupA,OppA
EqupB,OppA
EqupA,OppB
EqupB,OppB
EqupC,OppC
EqupA,OppD
EqupB,OppD
After Filter -
Equpc,Oppc
Please help!
Thanks
Kumar
-you want a Map<string,string>
-you want two entries in that map <Equpc,OppC> and <Equpc,OppE>
A map doesn't allow duplicate keys, so this result is impossible.
You should make EqpOppMap a Map<string,List<Opportunity>>.
All Answers
What do you want the result to be in your example if there is more than one Opp with EquipC?
After Filter -
Equpc,OppC
Equpc,OppE
-you want a Map<string,string>
-you want two entries in that map <Equpc,OppC> and <Equpc,OppE>
A map doesn't allow duplicate keys, so this result is impossible.
You should make EqpOppMap a Map<string,List<Opportunity>>.