+ Start a Discussion
Nicole ChanNicole Chan 

Restrict to change opportunity if owner is inactive

Hello All,

I am not a developer, so I am look for if anyone can help me as I really have no idea how to edit the following trigger.
Our use case is the developer wrote the below trigger to prevent user to change the opportunity if the user is inactive,
but this trigger also restrict system admin to edit record, right now, I have over 100+ opportunities need to make change, 
so would someone help me if this trigger allow system admin to edit even opportunity owner is inactive?


trigger taskoppstage on Opportunity (after update) {
      if(trigger.new[0].StageName != trigger.old[0].StageName || trigger.new[0].ForecastCategory != trigger.old[0].ForecastCategory) {
        Task t = new Task();
            t.Description = 'Opportunity Stage Updated:  ' + trigger.new[0].StageName + '\n' + 'Opportunity Name: ' + trigger.new[0].Name;
            t.whatId = trigger.new[0].AccountId;
            t.Status = 'Completed';
            t.OwnerId = trigger.new[0].OwnerId;
            t.Subject = 'Opp Update';
            insert t;   


Beside, I tried to inactive this trigger in sandbox and outbound the changes set, and below error shows, who can let me know how to fix it?

Error Message:-
This organization isn't authorized to upload change sets to other organizations. For authorization, contact the deployment connections administrators on the organizations where you want to upload changes.

thank you for help in advance=]
Akhil AnilAkhil Anil
Hi Nicole,

You don't really need a trigger to achieve. Instead you can simply create a validation rule on the Opportunity with the below formula
$Profile.Name <> "System Administrator"

This not allow any users except the system administrators to change the Opportunity if the owner is inactive.

Kindly mark it as an answer if that works !
Nicole ChanNicole Chan
Hi Akhil,
What do you mean is i should deactive this trigger and just set up the validation rule under opportunity then will have the same function to restrict anyone to edit the record except system admin?
Akhil AnilAkhil Anil
Exactly !