+ Start a Discussion
Deepak Pandey 13Deepak Pandey 13 

how to update case ownerid help of visualforce pages in detailed page?

help of picklist uptate owner of case.
1st picklst of user or queue  after come list of user or queue and commond button update update owner.


public class roleexten 
{
        public Case cse {get; set;}
        public String selectedId {get;set;}
        public List<selectoption> UserOptionList{get;set;}
        public list<Case> caselist{get; set;}
         public Id ownerid {get;set;}
        
        public roleexten(ApexPages.StandardController controller)
        {
        
       ownerid = ApexPages.currentPage().getParameters().get('id') ;
            caselist=[select id,ownerid from case where id=: ownerid ];
            cse  =new Case();
            system.debug('cse.ownerId:::::'+cse.ownerId);
            selected();
        }
        public pagereference assignowner()
        {
            return page.vfpageownerassign ;
        }
        
        
        public void selected()
        {
          system.debug('run:::::::::::::::');
            UserOptionList = new List<selectoption>();

            UserOptionList.add(new selectoption('','--None--'));
            system.debug('select :::::'+cse.ownerId);
            if(cse.assign__c == 'User')
       {
            for(User u :[select id ,name from user ])
            {
                system.debug('@@@@u' +u);
                UserOptionList.add(new SelectOption(u.Id , u.Name));
            }
        }
            //system.debug('@@@@UserOptionList' +UserOptionList );
      else if (cse.assign__c == 'Queue')
       {
      for(Group gp :[Select Name, Id From Group where Type = 'Queue'])
       { 
     UserOptionList.add(new SelectOption(gp.Id , gp.name));
       }    
  }
 }
 public void saveassign()
     {
        for(case c : caselist)
         {
             c.ownerid=selectedId;
         }
         update caselist;
     }
}

Page----
<apex:page standardController="Case" extensions="roleexten" sidebar="false">
 <apex:form >
  <apex:pageblock mode="edit" >
  <apex:commandButton value="save" action="{!saveassign}" />
   <apex:pageBlockSection >
    <apex:pageBlockSectionItem >
     <apex:inputField value="{!cse.assign__c}">
     <apex:actionSupport action="{!selected}" event="onchange" reRender="cont"/> 
     </apex:inputField>
    </apex:pageBlockSectionItem>
    </apex:pageBlockSection>
   
            <apex:outputPanel id="cont">
           <apex:pageblockSection title="Owner" >
                  <apex:selectList size="1" value="{!selectedId }">
                      <apex:selectOptions value="{!UserOptionList }"></apex:selectOptions>
                  </apex:selectList>
        
           </apex:pageBlockSection>
           </apex:outputPanel>
 

  </apex:pageblock>
 </apex:form>
</apex:page>
Best Answer chosen by Deepak Pandey 13
Deepak Pandey 13Deepak Pandey 13
public class roleexten 
{
        public Case cse {get; set;}
        public String selectedId {get;set;}
        public List<selectoption> UserOptionList{get;set;}
        public list<Case> caselist{get; set;}
        public string invoiceid{get;set;}
        
        public roleexten(ApexPages.StandardController controller)
        {
        
      invoiceid= ApexPages.currentPage().getParameters().get('id');
            
            cse  =new Case();
            system.debug('cse.ownerId:::::'+cse.ownerId);
            selected();
        }
        public pagereference assignowner()
        {
            return page.vfpageownerassign ;
        }
        
        
        public void selected()
        {
          system.debug('run:::::::::::::::');
            UserOptionList = new List<selectoption>();

            UserOptionList.add(new selectoption('','--None--'));
            system.debug('select :::::'+cse.ownerId);
            if(cse.assign__c == 'User' )
       {
            for(User u :[select id ,name from user ])
            {
                system.debug('@@@@u' +u);
                UserOptionList.add(new SelectOption(u.Id , u.Name));
            } 
        }
      else if (cse.assign__c == 'Queue')
       {
      for(Group gp :[Select Name, Id From Group where Type = 'Queue' ])
       { 
     UserOptionList.add(new SelectOption(gp.Id , gp.name));
       }    
  }
 }
 
 public void saveassign()
     {
       for(case c : [select id,ownerid from case where id =: invoiceid])
      {
          c.ownerid=selectedId;
          system.debug('@@@@@selectedId' +selectedId);
       update c;
     }
     }
}


<apex:page standardController="Case" extensions="roleexten" sidebar="false">
 <apex:form >
  <apex:pageblock mode="edit" >
  <apex:commandButton value="save" action="{!saveassign}" />
   <apex:pageBlockSection >
    <apex:pageBlockSectionItem >
     <apex:inputField value="{!cse.assign__c}">
     <apex:actionSupport action="{!selected}" event="onchange" reRender="cont"/> 
     </apex:inputField>
    </apex:pageBlockSectionItem>
    </apex:pageBlockSection>
   
            <apex:outputPanel id="cont">
           <apex:pageblockSection title="Owner" >
                  <apex:selectList size="1" value="{!selectedId }">
                      <apex:selectOptions value="{!UserOptionList }"></apex:selectOptions>
                  </apex:selectList>
        
           </apex:pageBlockSection>
           </apex:outputPanel>
 

  </apex:pageblock>
 </apex:form>
</apex:page>