+ Start a Discussion
Deepak Pandey 13Deepak Pandey 13 

case owner assign with the help of below criteria?

hi everyone.
shortout my problem ?
i have a two picklis
1st- custom picklist field (user and queue)
2nd- picklist(show list of user and queue)

my requirement after click select user then come user another picklist after select them click on command button case owner will be ssigned.

apex class---
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 roleexten(ApexPages.StandardController controller)
        {
            caselist=[select id,ownerid from case];
            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)
         {
         
         }
     }
}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 roleexten(ApexPages.StandardController controller)
        {
            caselist=[select id,ownerid from case];
            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)
         {
         
         }
     }
}

pages-
<apex:page standardController="Case" extensions="roleexten" sidebar="false">
 <apex:form >
  <apex:pageblock >
   <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:commandButton value="save" action="{!saveassign}" />
           </apex:pageBlockSection>
           </apex:outputPanel>
 

  </apex:pageblock>
 </apex:form>
</apex:page>
Siddharth ManiSiddharth Mani
I dont understand what the problem here is. Your code is complete except for the assigning part. I guess you can assign the case to User/Queue both using your code. Just change your controller as follows (only the last for loop has been changed. Rest all remain same):
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 roleexten(ApexPages.StandardController controller)
        {
            caselist=[select id,ownerid from case];
            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;
     }
}

 
Deepak Pandey 13Deepak Pandey 13
Actually this code update all case in my org. i just want to update only owner where user is same.