public void updateAccessLevelsOnUpdate(final List<Opportunity> newOppList, Map<Id, Opportunity> oldOppMap){
if(Istrue == true){
try{
Map<Id, Id> opportunityAssignedToMap = new Map<Id, Id>();
Set<String> uniqueOppUserCombination = new Set<String>();
for(Opportunity opp :newOppList){
**if(opp.Assigned_To__c != oldOppMap.get(opp.Id).Assigned_To__c && opp.Assigned_To__c != null){
opportunityAssignedToMap.put(opp.Id, opp.Assigned_To__c);**
uniqueOppUserCombination.add(opp.Id+'_'+opp.Assigned_To__c);
}
}
List<OpportunityTeamMember> oppTeamMemberList = new List<OpportunityTeamMember>();
oppTeamMemberList = getOpportunityTeamMember(opportunityAssignedToMap);
if(oppTeamMemberList.size() > 0){
Insert oppTeamMemberList;
}
List<OpportunityShare> opportunityShareList = new List<OpportunityShare>();
opportunityShareList = getOpportunityShareList(opportunityAssignedToMap, uniqueOppUserCombination);
if(opportunityShareList.size() > 0){
update opportunityShareList;
}
}
catch(exception e){for(Opportunity opp :newOppList) opp.addError('Sorry- '+e.getMessage());}
}
}
Test class
@isTest(seeAllData=false)
public Class OpportunityTriggerHandler_Test{
static testMethod void updateAccessLevelsOnInsert_test()
{
Test.startTest();
init();
Opportunity opp= [select ID , Assigned_To__c,Name from Opportunity where property__c =: newproperty.Id limit 1];
opp.Name = 'Suresh';
update opp;
newopportunity.add(opp);
Map <id,Opportunity> oldOppMap= new map<id,Opportunity>();
Opportunity OpportunityID= [select ID , Assigned_To__c from Opportunity where property__c =: newproperty.Id limit 1];
oldOppMap.put(newUser.Id,OpportunityID);
OpportunityTriggerHandler Opportunityobj =new OpportunityTriggerHandler();
Opportunityobj.updateAccessLevelsOnUpdate(newopportunity,oldOppMap);
Test.stopTest();
}
}