1

I have used the following code . Here It is creating new records rather than updating the existing One. I need to update the record . Pls suggest.

<apex:page standardController="Case"  extensions="QueueController" sidebar="false" showHeader="true" showChat="false" >
    <apex:form >
    <apex:pageBlock title="Select A Queue">
    <apex:pageBlockSection columns="4" title="Select A Queue">
         <apex:pageBlockSectionItem >
            Select Queue :
          </apex:pageBlockSectionItem> 
          <apex:pageBlockSectionItem >  
               <apex:selectList size="1" value="{!queue}">
                  <apex:selectOptions value="{!QueueList}"></apex:selectOptions>
               </apex:selectList> 
           </apex:pageBlockSectionItem>  
    </apex:pageBlockSection>
    <apex:pageBlockSection columns="4"  >
        <apex:pageBlockSectionItem >
            <apex:commandButton value="Save" action="{!saveCase}" id="save"/>
        </apex:pageBlockSectionItem>
        <apex:pageBlockSectionItem >
           <apex:commandButton value="Cancel" action="{!cancel}" id="cancel"/>
        </apex:pageBlockSectionItem>
    </apex:pageBlockSection>
  </apex:pageBlock>
   </apex:form>
</apex:page>



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>();

           // update this.caseObj;
        }

     public PageReference saveCase(){
            caseobj.ownerid = queue;
            upsert caseobj;
            PageReference ref = new PageReference('/'+caseobj.id);
            return ref;
}
    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;
        }

}
6
  • Try remove the final keyword when defining your caseObj variable Jul 14 '14 at 1:23
  • I am still getting a new case created... while I just want to update my record. Jul 14 '14 at 1:35
  • If you do update instead of upsert, does that update the same record or you're getting errors? Jul 14 '14 at 1:36
  • I am getting error for that Jul 14 '14 at 1:54
  • What is the error? Jul 14 '14 at 1:55
3

Are you opening the VF page with an id in the query string? If you aren't, then the

  this.caseObj = (Case)controller.getRecord();

will generate a new case. That would be my guess as to what is happening. Especially if the error is about not being able to update the record due to missing id.

2
  • can u pls suggest how can we update it ? Jul 14 '14 at 2:05
  • 3
    When you call the page, you need to specify the id of the case you are trying to update, something like this: /apex/caseQueue?id=500xxxxxxxxxxxx Or, if you are overriding the view or edit pages for the case, this is done for you.
    – JimRae
    Jul 14 '14 at 2:07

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.