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
Shephali SwarnkarShephali Swarnkar 

working with list

Hi all,
     I have a list where i am passing the value of Sobject(id and name).but now i need to fetch the Alias for the user which user's name is being selected from the list.how to get this???
public class report
 {
  public list<selectoption> options{get;set;}
  public User b{get;set;}
  public Boolean isSelected{get;set;}
  public Id SelectedOwnerId{get;set;}
  public report()
  {
  getoptions();  
  }
  
  public list<selectoption> getoptions()
  {
     options = new list<selectoption>();
     for(user b : [Select Id, Name, Alias from User where IsActive = true Order by Name])
     {
       options.add(new selectoption(b.Id,b.Name));
     }
     return options;
 }
Best Answer chosen by Shephali Swarnkar
Venkat HVenkat H
Hi Shephali Swarnkar,
   
Check the below code it will work fine. if you need any clarification contact me!!!!

<apex:page controller="report">
  <apex:form id="frm">
      <apex:selectList size="1" value="{!SelectedOwnerId}">
          <apex:selectOptions value="{!options}"/>
          <apex:actionSupport event="onchange" reRender="frm" action="{!sel}"/>
      </apex:selectList>
      <apex:outputText >{!Name}</apex:outputText>
  </apex:form>
</apex:page>
public class report
 {
 public list<selectoption> options;
  public User b{get;set;}
  public Boolean isSelected{get;set;}
  public Id SelectedOwnerId{get;set;}
  public String Name{get;set;}
  public Map<id,User> userMap;
  public report()
  {
  userMap=new Map<id,User>([Select Id, Name, Alias from User where IsActive = true Order by Name]);
   
  }
  
  public Void sel(){
      Name=userMap.get(SelectedOwnerId).Name;
  }
  
  public list<selectoption> getoptions()
  {
     options = new list<selectoption>();
     for(user b : userMap.values())
     {
       options.add(new selectoption(b.Id,b.Name));
     }
     return options;
 }
}

All Answers

Venkat HVenkat H
Hi Shephali Swarnkar,
   
Check the below code it will work fine. if you need any clarification contact me!!!!

<apex:page controller="report">
  <apex:form id="frm">
      <apex:selectList size="1" value="{!SelectedOwnerId}">
          <apex:selectOptions value="{!options}"/>
          <apex:actionSupport event="onchange" reRender="frm" action="{!sel}"/>
      </apex:selectList>
      <apex:outputText >{!Name}</apex:outputText>
  </apex:form>
</apex:page>
public class report
 {
 public list<selectoption> options;
  public User b{get;set;}
  public Boolean isSelected{get;set;}
  public Id SelectedOwnerId{get;set;}
  public String Name{get;set;}
  public Map<id,User> userMap;
  public report()
  {
  userMap=new Map<id,User>([Select Id, Name, Alias from User where IsActive = true Order by Name]);
   
  }
  
  public Void sel(){
      Name=userMap.get(SelectedOwnerId).Name;
  }
  
  public list<selectoption> getoptions()
  {
     options = new list<selectoption>();
     for(user b : userMap.values())
     {
       options.add(new selectoption(b.Id,b.Name));
     }
     return options;
 }
}
This was selected as the best answer
Shephali SwarnkarShephali Swarnkar
Thanks Venkat!!
Shephali SwarnkarShephali Swarnkar

Hi Venkat!!!
       Can we count how many checked checkboxes we have in a field with checkbox datatype.if yes how?query for same.!!
Venkat HVenkat H

Hi Shephali Swarnkar,

Please refer the below code to count no.of checked chekbox, the bolded code is used to get checked checkbox condition. If you have any queries post here.

Code:
select count(id) from sObject(Ex: Account) group by Checkbox Api Field(Ex: Active_Account__c) having Checkbox Api Field(Ex: Active_Account__c)=true