You need to query user everytime your owner change on layout
public string profile{
get{
for(User u: [SELECT Id, Profile.Name FRom User WHERE Id =:Opportunity.OwnerId LIMIT 1]){
profile = u.Profile.Name;
system.debug('u.Profile.Name');
}
return profile;
}
set;
}
You need to update you getItem
section as
public List<SelectOption> getItems() {
for(User u: [SELECT Id, Profile.Name FRom User WHERE Id =:Opportunity.OwnerId LIMIT 1]){
profile = u.Profile.Name;
List<SelectOption> options = new List<SelectOption>();
If(profile == 'Q-Sales-EI'){
options.add(new SelectOption('Employee Insights','Employee Insights'));
}
else If(profile == 'Q-Sales-Enterprise'){
options.add(new SelectOption('Enterprise','Enterprise'));
}
else If(profile == 'Q-Sales-K12'){
options.add(new SelectOption('K-12','K-12'));
}
else If(profile == 'Q-Sales-RS'){
options.add(new SelectOption('Research Suite Corp','Research Suite Corp'));
}
else If(profile == 'Q-Sales-SLG'){
options.add(new SelectOption('Enterprise','Enterprise'));
}
else If(profile == 'Q-Sales-Academic'){
options.add(new SelectOption('Academic','Academic'));
options.add(new SelectOption('Enterprise','Enterprise'));
}
return options;
}
Also for everything you have created get method.In get method its hard to manage code execution because required or not whenever page rerenderrerender
they execute again. increase the CPU time and in your case will increase number fof SOQL as well.