0

I have the following code..but i am not able to use the selected value to set the value for case object . Please help.

    <apex:pageBlock title="Select A Queue">
    <apex:pageBlockSection title="Select A Queue">

           <apex:selectList size="1">
               Select Queue :   <apex:selectOptions value="{!QueueList}"></apex:selectOptions>

           </apex:selectList> 
         <br/><br/>

           <apex:commandButton value="Save" action="{!save}" id="save" />
           <apex:commandButton value="Cancel" action="{!cancel}" id="cancel"/>

    </apex:pageBlockSection>
  </apex:pageBlock>  

</apex:form>

   public class QueueController {
   public List<Group> GroupNameList  = new List<Group>();

private final Case caseObj;

public QueueController (ApexPages.StandardController controller) {
              this.caseObj = (Case)controller.getRecord();
        }

public List<SelectOption> QueueList 
{
    get
    {
        GroupNameList  = [select g.Id, g.Name from Group g where Type = 'Queue'];

        QueueList = new List<SelectOption>();

        for(Group temp : GroupNameList)
        {
            QueueList.add(new SelectOption(temp.Id, temp.Name));
        }
        return QueueList;
    }
    set;
    }

}
2

Can you please try the below code :

For controller:

public class QueueController {
   public List<Group> GroupNameList{get;set;}

    private final Case caseObj{get;set;}

    public String queue {get;set;}

    public QueueController (ApexPages.StandardController controller) {
              this.caseObj = (Case)controller.getRecord();
            GroupNameList = new List<Group>();
        }


    public List<SelectOption> QueueList 
    {
        get
        {
            GroupNameList  = [select g.Id, g.Name from Group g where Type = 'Queue'];

            QueueList = new List<SelectOption>();

            for(Group temp : GroupNameList)
            {
                QueueList.add(new SelectOption(temp.Id, temp.Name));
            }
            return QueueList;
        }
        set;
        }

}

public PageReference saveCase(){
    caseobj.ownerid = queue;
    upsert caseobj;
    PageReference ref = new PageReference('/'+caseobj.id);
    return ref;
}

For VF page:

<apex:pageBlock title="Select A Queue">
    <apex:pageBlockSection title="Select A Queue">
            Select Queue :
           <apex:selectList size="1" value="{!queue}">
                  <apex:selectOptions value="{!QueueList}"></apex:selectOptions>

           </apex:selectList> 
         <br/><br/>

           <apex:commandButton value="Save" action="{!saveCase}" id="save" />
           <apex:commandButton value="Cancel" action="{!cancel}" id="cancel"/>

    </apex:pageBlockSection>
  </apex:pageBlock>
  • public QueueController (ApexPages.StandardController controller) { this.caseObj = (Case)controller.getRecord(); GroupNameList = new List<Group>(); this.caseObj.ownerid = queue.getValue; } will this be used to extract the value out of it? – user2703132 Jul 11 '14 at 14:59
  • Instead of queue.getValue use "this.caseObj.ownerid = queue" – tandonprateek Jul 11 '14 at 15:01
  • After adding that line of code ... on click of save I am not able to navigate back on the case page... can u pls tel why is it so... how can we send the data pack to update the field on case page – user2703132 Jul 11 '14 at 15:11
  • are you doing the above code in controller? – tandonprateek Jul 11 '14 at 15:12
  • I have added this for overriding but it is still not working for me public PageReference save() { TRY { this.caseObj.ownerid = queue; update this.caseObj; PageReference newpage = new PageReference(System.currentPageReference().getURL()); newpage.setRedirect(true); return newpage; } catch(System.DMLException e) { ApexPages.addMessages(e); SYSTEM.DEBUG('ERROR :'+e); return null; } return null; } – user2703132 Jul 11 '14 at 15:15
0

You need to add a property in the class to store a string

In the <apex:selectlist>you put that property in the value= tag

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.