You need to sign in to do that
Don't have an account?
get employee records based on deptartment number selection
i have created emp2__c object for employees and dep2__c object for department. , emp2__c is related to dep2__c (lookup). if i select deptName and press btton go i should view the records of corresponding employees associated with department name . but instead am getting ids. help me in this issue.
controller:
public class departmentConrtroller
{
List<dept2__c> deptList;// departmentList
List<emp2__c> employeesList;//employeeList
String departmentNumber='10';
public departmentConrtroller()
{
deptList =[select Id,name,dept2No__c,Location__c from dept2__c];
}
//select options
public List<SelectOption> getdepartmentItems()
{
List<selectOption> options = new List<selectOption>();
for(dept2__c dept : deptList)
{
String departmentNumber1 =String.valueOf(dept.dept2No__c);
options.add(new selectOption(departmentNumber1,dept.name));
}
return options;
}
public String getdepartmentNumber()
{
return departmentNumber;
}
public void setdepartmentNumber(String departmentNumber)
{
this.departmentNumber=departmentNumber;
}
public List<emp2__c> getemployees()
{
Id id=[select Id from dept2__c where dept2No__c=:departmentNumber].ID;
employeesList=[select name,employeeId__c, salary__c,Address__c from emp2__c where dept2No__c=:id];
return employeesList;
}
public PageReference go()
{
return null;
}
}
visualpage: sx
<apex:page controller="departmentConrtroller">
<apex:form >
<apex:selectList value="{!departmentNumber}">
<apex:selectOptions value="{!departmentItems}"/>
</apex:selectList>
<apex:commandButton value="go" action="{!go}"/ >
</apex:form>
<apex:outputText value="{!employees}"/>
</apex:page>
I think this is because you are simply rendering the employee list via an outputText component - this will generate the string representation of the employee list, which could well be just the ids.
It would be better to iterate the list in some way - via a datatable for example:
All Answers
I think this is because you are simply rendering the employee list via an outputText component - this will generate the string representation of the employee list, which could well be just the ids.
It would be better to iterate the list in some way - via a datatable for example:
thanks mate it worked!!