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
Dru - Cloud62Dru - Cloud62 

Generic Standardcontroller

I need to build a component that can be put in any standard page layout. I cannot find a way to have it show up in the list without choosing a specific object for the standardcontroller.

I tried using sObject as a standardcontroller and there isn't one for that.

Is there a way to have the page available for all standard pages?

 

 

The standard controller method getId is all I need, which doesn't require a type so why am I forced to specify the object in the standardcontroller attribute?

sfdcfoxsfdcfox

StandardController requires a literal, and it triggers metadata changes (namely, a page with a standard controller can override buttons and be placed in the layouts of the named object). I have one of these in my project, and the design looks like this:

 

<apex:component controller="..." selfclosing="true">
  <apex:attribute assignTo="{!parent}" name="parent" description="The record to use." required="true" type="sobject"/>
</apex:component>
<apex:page standardController="Account">
  <c:myComponent record="{!Account}"/>
</apex:page>

This way, you need make only one-liner pages (well, three, but you get the idea) to generate each page, and modifying the component will affect all pages at once.

 

If you do NOT need a standardController, you can just pass the record ID and entity type directly through URL parameters (which we have other pages that do this, too). This eliminates the ability to override and embed, but allows you to use the page generically, as per your design. You can use custom buttons and/or links to pass the correct parameters.

 

And yes, I do wish there was a way to use a generic SObject standard controller, as our project badly needs that feature to reduce the number of pages we have by about 4 times over.