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
BryanTSCBryanTSC 

Should I use component attributes or some other method?

I am in the process of converting one of my VF pages to a component so that it can be easily reused across objects.

 

In my VF page I implement a standard controller with an extension class.  The constructor of my extension class pulls in the record from the standard controller so I can perform some describe methods on it:

 

public myControllerExtension(ApexPages.StandardController controller) {
        
        Schema.DescribeSObjectResult objDescribe = controller.getRecord().getSObjectType().getDescribe();
        ...
}

What is the best way to replicate this in the component controller?  I'm aware that the component controller does not have access to the standard controller, with the exception of using attributes to pass some information in.  Are attributes the right way to go?  Would I use an extension class in my page to generate the necessary values to assign to my controller attributes?

 

Thanks in advance for your assistance!

Best Answer chosen by Admin (Salesforce Developers) 
sfdcfoxsfdcfox

I actually have an extension class for the very purpose of communicating with my components when I need to. It's simple:

 

public with sharing class StandardControllerExtension {
  public ApexPages.StandardController StandardController { get; set; }
  public StandardControllerExtension(ApexPages.StandardController controller) {
    standardController = controller;
  }
}

Then, I name that as an attribute in my component so I can pass in my record via the standard controller. The great part is, it gives me component-level access to {!save}, {!cancel}, {!delete}, {!view}, and so on. Those six lines of code above give you a great standardization point.

All Answers

sfdcfoxsfdcfox

I actually have an extension class for the very purpose of communicating with my components when I need to. It's simple:

 

public with sharing class StandardControllerExtension {
  public ApexPages.StandardController StandardController { get; set; }
  public StandardControllerExtension(ApexPages.StandardController controller) {
    standardController = controller;
  }
}

Then, I name that as an attribute in my component so I can pass in my record via the standard controller. The great part is, it gives me component-level access to {!save}, {!cancel}, {!delete}, {!view}, and so on. Those six lines of code above give you a great standardization point.

This was selected as the best answer
BryanTSCBryanTSC
Awesome - thank you!