I have a variable, that is set in a method of an Apex class that is set as the controller of a custom VF page:

public without sharing class HomeController{
  public HomeController(){
  public List<People__c> people;
  public void init(){
    people = [my soql]

I now want to access this people variable in another Apex class - caveat being that this Apex class is the controller for a VF Component that is loaded through the Template of the same VF page. How would I go about doing this?

  • 1
    Why not just pass it through using <apex:attribute>?
    – Adrian Larson
    Commented Sep 22, 2016 at 20:59

1 Answer 1


Usually when I have data I've already spent governors acquiring, I pass it through using the <apex:attribute> tag in my component. On the receiving end, it would look like:

    <apex:attribute name="people" type="People__c[]" description="..." />

Then, on the page itself:

<c:myComponent people="{!people}" />

You can get fancier than that, but I've never had a need to do so.

  • 1
    I was about to get fancier than that, but then I'd just be duplicating effort.
    – sfdcfox
    Commented Sep 22, 2016 at 21:19

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .