function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Niraj Kumar 9Niraj Kumar 9 

trigger want to add the functionality that if opportunity owner role = sales specialist then no change in opportunity owner

Hi,

I want to make changes that if  opportunity owner role is 'sales specialist' then no change in opportunity owner and for other role
trigger tocUpdateOpportunitySalesTeamForAccountOwnerChange on Account (before update) 
{
    ID[] acc=new ID[]{};
    ID[] OwnerIds=new ID[]{};
    ID[] oldOwnerIds=new ID[]{};
    ID[] oppIds=new ID[]{};
    
    // List<Opportunity> oppToUpdate = new List<Opportunity>();
    
    List <String> OppOldOwnrLst = new List<String>();
    
    for (Integer i = 0; i < Trigger.new.size(); i++) 
    {           
         String id = Trigger.new[i].Id;
         if(Trigger.new[i].trZuoraID__c==null)
         {
            if (Trigger.new[i].OwnerId != Trigger.old[i].OwnerId) 
            {
                acc.add(Trigger.new[i].Id);
                OwnerIds.add(Trigger.new[i].OwnerId);
                oldOwnerIds.add(Trigger.old[i].OwnerId);                                 
            }
         }
    }
    
    System.Debug('acc'+acc+'acc.size'+acc.size());
    System.Debug('OwnerIds'+OwnerIds+'OwnerIds.size'+OwnerIds.size());
    System.Debug('oldOwnerIds'+oldOwnerIds+'oldOwnerIds.size'+oldOwnerIds.size());
  
    if(acc.size()>0)
    {
          
        for(Opportunity opp1:[Select Id,OwnerId, StageName, AccountId from Opportunity Where AccountId IN:acc])
        {
                     System.Debug('opp1.OwnerId'+opp1.OwnerId);
             
             if(opp1.StageName != ('6. Order Placed') && opp1.StageName != ('7. Order Complete') && opp1.StageName != ('8. Closed / No Order'))
            {
                oppIds.add(opp1.Id);
                OppOldOwnrLst.add(opp1.id+';'+opp1.OwnerId);                       
               
            }
        }
   
            //ProcessDataAccount Class Method Called
                
            //ProcessDataAccount.AssignData(acc,OwnerIds,oppIds,oldOwnerIds,OppOldOwnrLst);
    }   
}

opportunity owner= Account owner.

Here is my code