1

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(){
    init();
  }
  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
  • 1
    Why not just pass it through using <apex:attribute>? Commented Sep 22, 2016 at 20:59

1 Answer 1

5

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:component>
    <apex:attribute name="people" type="People__c[]" description="..." />
</apex:component>

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
  • 1
    I was about to get fancier than that, but then I'd just be duplicating effort. Commented Sep 22, 2016 at 21:19

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.