[SalesForce] the standard Controller, and what can it access

Suppose I have this URL where a VF page points to a record: https://c.cs16.visual.force.com/apex/oppTest?id=006a0000012Wb4s . In my VF below, I get that the standard controller gets that record from the sObject. In my VF page, what are the limits to what I can access? Standard fields, and custom ones seem to be ok. It also lets me traverse relationships ( say from Opp –> Account–> User …). Can I also get children records? if so how?

<apex:page standardController="Opportunity" >
<apex:outputField value="{!Opportunity.name}"/>
<apex:outputField value="{!Opportunity.Account.createdby.name}"/>
<apex:outputField value="{!Opportunity.Account.createdby.custom__c}"/>
<apex:outputField value="{!Opportunity.CreatedBy.name}"/>

</apex:page>

Best Answer

StandardController, or, more formally, ApexPages.StandardController, is a system class that exposes functions for various things you'd want to do with a record.

It can add additional fields to the default record query (addFields) or reset the internal state (reset), return to the last page without performing any action (cancel), save and go on (save), return an edit page (edit), get the record (getRecord) or record's ID (getId), and return a link to the detail page (view).

The primary purpose of this class is to emulate UI actions programmatically, and extend the query parameters for an extension class in a Visualforce page. StandardController is responsible for building the SOQL that will eventually be used by the Visualforce page to render the page.

Normal SOQL limits apply, meaning you can only go "up" four relationships, and "down" one relationship. This means you can't get the parent's parent's parent's parent's parent's name, nor can you get grandchildren records. Note that you don't explicitly specify which relationships you want to query normally, as they are derived from the Visualforce code.

See the documentation for StandardController for further explanation of this class.

Curiously, the last time I played around with this class, I noticed that calling save() does not increase the DML rows or DML count for a transaction, but saving records this way is inefficient and not recommended for bulk saving.