public void updateAccessLevelsOnUpdate(final List<Opportunity> newOppList, Map<Id, Opportunity> oldOppMap){
        if(Istrue == true){
            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);**

            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

    public Class OpportunityTriggerHandler_Test{

    static testMethod void updateAccessLevelsOnInsert_test()


      Opportunity opp= [select ID , Assigned_To__c,Name from  Opportunity where property__c =: newproperty.Id limit 1];       
      opp.Name = 'Suresh';
      update 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];     

      OpportunityTriggerHandler Opportunityobj =new OpportunityTriggerHandler();       


  • 1
    People will get a more chance to help you here if you can provide more information such as what is the difficulty you are facing, any errors you receive, applicable code snippets from the trigger, etc. – highfive Mar 6 '19 at 11:25

To make this code enter it's body:

if(opp.Assigned_To__c != oldOppMap.get(opp.Id).Assigned_To__c && opp.Assigned_To__c != null) {

assuming your code is called from a trigger, you will need to modify the Assigned_To__c value of one or more of the Opportunities you create in your code.

Assuming the field isn't defaulted to the current User this should be enough:

  opp.Name = 'Suresh';
  opp.Assigned_To__c = UserInfo.getUserId();
  update opp;

If it is already set to the current User, you will need to create a new User in your test code and use the Id of that; Google for examples.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy