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
preddypreddy 

restrict owners assign case from user to queue

Hi

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;
               try{
        update c;
        }catch(Exception ex){
               
                String err = ex.getMessage();
                if(err.contains('INSUFFICIENT_ACCESS_OR_READONLY'))
                    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);
             p3.setRedirect(true);

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

        return p3;
    }
    }

 

Thanks in Advance.

 

Regards,

 

Praveen Reddy

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