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
SPDSPD 

How to pass a list from a custom component to the controller?

hi,

 

Im new to salesforce and im trying out some simple things first.

 

I am having two custom objects :- Employee__c and Department__c

 

Employee__c has a lookup for department__c.

 

What i want to do is  display all the employees associated with a particular department in one single row.(Two columns :- Departments and Employees)

 

 

for eg:- if ther are two departments:-

 

1) Sales 2)HR

 

then the page should look like:

 

Sales(under departments column)  -  xyz, pqr, etc(in employee column)   

 

For that purpose i've the following class:-

 

 

public class EmpList2
{   
   
   public List<Department__c> lstDepartment = new List<Department__c>();
  
    
    public EmpList2(ApexPages.StandardController Ctlr )
    {  
               
           
        lstDepartment = [select name,(Select Name From Employees__r) from department__c];
        system.debug('---lstdept---'+lstDepartment);
                        
    }
   
  
    public List<department__c> getListDpt()
    {
        return lstDepartment;
    }
        

}

 

 

and the following visualforce page ..

 

 

 

<apex:page standardController="Employee__c" extensions="EmpList2">
<apex:form >
<apex:sectionHeader title="Employee List" subtitle="(All Departments)"/>
<apex:pageBlock title="Employees">
<apex:pageblocktable value="{!ListDpt}" var="item1" id="pb">
<apex:column headerValue="Departments">{!item1.name}</apex:column>
<apex:column headerValue="Employees" >
      <c:myComponent record="{!item1.employees__r}"></c:myComponent>
</apex:column>
</apex:pageblocktable>
</apex:pageBlock>
</apex:form>
</apex:page>

 

 

also im trying to have my own custom component(myComponent)..i am passing the records recived(i guess that is a list....item1.employees__r)  to a custom component which is as follows :-

 

 

<apex:component >
<apex:attribute name="record" description="Create a link(outputLink)" type="Employee__c[]" ></apex:attribute>
<apex:outputLink value="/someurl">{!record) </apex:outputLink>
</apex:component>

 

when i use this code the output i am getting is 

 

department names under departments column...but i am not getting the employee names under employee column....instead i am getting their ids...but that to inside a sqaure bracket like the one below:

 

 

column 1 : department name         column 2: - [a0190000000c26QAAQ, a0190000000c2A8AAI, a0190000000c2U4AAI],

 

 

 

so please help me find a solution over it...do i need to use a seperate class for a custom component too?

 

if yes..then how am i going to pass the list to the component's controller?

 

 

Thanks in advance.  

 

 

Best Answer chosen by Admin (Salesforce Developers) 
bob_buzzardbob_buzzard

You are seeing this because you have passed in an array of Employee__c records and simply output a text representation of that list.

 

You probably want to use a datatable or repeat component to iterate the list and output the Name of each element. 

All Answers

bob_buzzardbob_buzzard

You are seeing this because you have passed in an array of Employee__c records and simply output a text representation of that list.

 

You probably want to use a datatable or repeat component to iterate the list and output the Name of each element. 

This was selected as the best answer
SPDSPD

Hey Thanks alot...I used repeat...it worked...i tried using datatable..but it showed blank...

 

one more question...

 

if i use assignTo attribute of  attribute tag,then is it possible to assign the list(in this case 'record')  to another list in the custom components controller?

 

 

Thanks again. :)

bob_buzzardbob_buzzard
Yes, that should work.  
KruthiiiKruthiii
Hi SPD,
I am working on the same kind of requriement, Can you please let me know were you able to use the assignTo attribute of the component and pass the list(in this case 'record')  to another list in custom component controller?
If so, can you please guide me how? Because all the time i pass the list from component to custom component controller it is NULL and getting a NULL pointer exception.
Any help is appreciated.