+ Start a Discussion

restrict owners assign case from user to queue


i have requirement where i have implemeted custom change owner rathen than standard owner change.here i need to restrict some of the users to assign a case to queue.i mean those users who are having role "executive" and "specialist" not eligible to transfer a case to queue.


here is the snippet.


i have highlited a line where i am facing the problem.


what i am trying to write a condition is if the user role is executive he should  not assign a case to queue.but he can assign to user.


public with sharing class CaseExtension
    private final Case c;
    public User userProfile {get;set;}
    public Case caserec{get;set;}
    public Id getId {get;set;}
    integer counter=0;
    public CaseExtension(ApexPages.StandardController sc)
        this.c = (Case)sc.getRecord();
        userProfile = [SELECT Id,Name,UserRole.Name,Profile.Name  FROM user where Id =: userInfo.getUserId()];
    public PageReference updateCaseOwner()
       if(userProfile.UserRole.Name=='GBS IPAS Executive'&& c.OwnerId != 'User'){
         ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR,'You should not transfer to Queue'));   
         return null;
              c.Owner_Update__c = True;
        update c;
        }catch(Exception ex){
                String err = ex.getMessage();
                    err = 'You do not have sufficient access to perform the necessary action. Please contact the record owner';

                ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, err));
                return null;

        pageReference p3 = new PageReference('/' + c.Id);

        system.debug('value of p3: ' + p3);

        return p3;


Thanks in Advance.




Praveen Reddy

Just use a validation rule. You won't want to override this with Visualforce, because it can be bypassed.