You need to sign in to do that
Don't have an account?
MOHAMMED AL IMAM
Hi anyone please provide the test class for below code
trigger campaigntrigger on CampaignMember (after insert) { Map<id,List<opportunity>> map1 = new Map<id,List<opportunity>>(); set<id> conSet =new set<id>(); for(CampaignMember c :trigger.new ){ conSet.add(c.contactId); } for(opportunity cm: [select id,contactId,Name,StageName from opportunity where contactid in: conSet]){ List<opportunity> oppList; if(!map1.containsKey(cm.contactId)){ oppList = new List<opportunity> (); oppList.add(cm); map1.put(cm.contactId, oppList); system.debug('success' +map1); } else{ oppList = map1.get(cm.contactId); oppList.add(cm); map1.put(cm.contactId,oppList); system.debug('fail' +map1); } } List<Opportunity> oppsToUpdate = new List<Opportunity>(); for(CampaignMember cm : trigger.new){ if(cm.ContactId != NULL){ if(map1.get(cm.ContactId) != NULL){ for(Opportunity op : map1.get(cm.ContactId)){ op.CampaignId = cm.CampaignId; oppsToUpdate.add(op); } } } } if(oppsToUpdate.size() > 0){ update oppsToUpdate; } }
Try Below Test Class (100% Coverage) Please Mark it As Best Answer If It Helps
Thank You!
Please Close Your Query By Marking it As Best Answer If It Helps So It Helps Others In Future
Thank You!
Please follow the below code:-
Please mark it as Best Answer if it helps you.
Thanks & Regards
Suraj Tripathi