Skip to main content
2 of 3
More detail
Tyager
  • 574
  • 8
  • 15

Visualforce page and Visualforce component

I am working on a project right new and I just noticed something, that makes sense, but I did not realize it.

The Visualforce page and the Visualforce component both use the same controller. Now correct me if I am wrong, but when the Visualforce component is called from the Visualforce page, the component will then instantiate the controller again and have its own instance of the controller.

This is essentially doubling the amount of SOQL depending on the code used (if you have many SOQL in the constructor). If what I am saying is correct, could you see a way to pass in a pointer to the component, from the page, that will indicate to use the already instantiated controller? I do not believe something like this is possible currently, but that is my thought on how it could be done in future instances if they were to make this possible.

I noticed this when I called a component from repeat in the visualforce page, and then I called a component from repeat in the previously created component. I had 5 SOQLs in my constructor, and this led to me hitting the SOQL limit on page load. I believe this was due to the 2nd component being called so much and doing the 5 SOQLs over and over again.

I'm looking for clarification to see if what I am saying is correct in this matter.

Tyager
  • 574
  • 8
  • 15