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
Soundar Rajan PonpandiSoundar Rajan Ponpandi 

display all Queues in visualforce page by Dropdown

HI,

I like to update a Queue Owner ,

1. Display all queue's in visualforce page
2. select a Queue by dropdown 
3. Update current owner by click save button.


Can anyone explain how i can achieve this Process.

Thanks,
Soundar. 
Best Answer chosen by Soundar Rajan Ponpandi
Soundar Rajan PonpandiSoundar Rajan Ponpandi
Solved,

Class

Public Class QueueOwnerUpdate{
    
    public List<Group> grp= new List<Group>();
    private final Case caseObj{get;set;}
    public String queue1 {get;set;}
    Public String caseId{get;set;}
    
    public QueueOwnerUpdate() {
    }
    
    public List<SelectOption> QueueList{
        get
        {
            grp = [Select Id, Name, Type From Group where Type = 'Queue'];
            QueueList = new List<SelectOption>();
            QueueList.add(new SelectOption('--None--', '--None--'));
            for(Group q : grp)
            {
                QueueList.add(new SelectOption(q.Id, q.Name));
            }
            System.debug('Selected Queue | ' + QueueList);
            return QueueList;
        }
        set;
    }
    
    public PageReference saveCase(){
        Try{
            IF(queue1 == '--None--'){
                ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR,'Pleae Select a Queue from dropdown'));
            }else{
                caseId  = ApexPages.CurrentPage().getparameters().get('id');
                Case caseRecord = [Select Id, CaseNumber,ownerId from Case Where Id =: caseId];
                caseRecord.OwnerId = queue1;
                update caseRecord;
                PageReference ref = new PageReference('/'+ caseRecord.id);
                return ref;
            }
        }Catch(Exception e){
            ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR,'Pleae Select a Queue from dropdown'));
        }
        return Null;
    }
}

VF
<apex:page controller="QueueOwnerUpdate" showHeader="true" sidebar="true" tabStyle="Case">
    <apex:form >
        <apex:pageBlock title="Select a Queue For Update  Owner" >
                    <apex:pageMessages />
            <apex:pageBlockSection title="Select a Queue">
                <apex:selectList size="1" value="{!queue1}">
                    <apex:selectOptions value="{!QueueList}"></apex:selectOptions>
                </apex:selectList> <br /><br /><br/>
                <center>
                    <apex:commandButton value="Change Owner" action="{!saveCase}" id="save" />
                </center>
            </apex:pageBlockSection>
        </apex:pageBlock>
    </apex:form> 
</apex:page>

Regards,

Soundar.​​