How Standard Controller works ?
Standard controller is nothing but a standard object which will give access to sObject & all its standard actions. So, this will be applicable to both standard and custom controller.
What fields are included ?
When you load a page for a record by passing id value, standard controller doesn't load with all the fields for the record. Because, that is unnecessary. So, it will fetch only the fields used in visualforce page/components tree.
What are all the ways to include fields ?
So, either you can add the fields in the page using any standard output/input tags (or) you can use addFields() API in standard controller to pass the list of fields in the controller/extension side.What is the easiest way ?
But, when you don't want to actually display the fields, but what them to process something in Apex Controller/Extension, you could do one of the following trick to force include,- OutputField/inputField with rendered=false
- use inputHidden
Where is the code ?
The following example used OutputField & inputHidden tag to actually force including the fields in the Standard Controller.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class testcls7_12122016 { | |
public String name_with_createddate {get; set;} | |
public testcls7_12122016(ApexPages.StandardController sc) { | |
Account ac = (Account) sc.getRecord(); | |
name_with_createddate = ac.Name + '###' + ac.CreatedDate; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<apex:page standardController="Account" extensions="testcls7_12122016"> | |
<apex:form> | |
<!-- Using OutputFiled - Use rendered=false --> | |
<apex:outputField value="{!Account.CreatedDate}" rendered="false"/> | |
<!-- Using input hidden field --> | |
<apex:inputHidden value="{!Account.Name}"/> | |
</apex:form> | |
<!-- Output to User --> | |
<apex:outputText value="The Account name with Created Date - {!name_with_createddate}" | |
style="font-size:25px;"/> | |
</apex:page> |
no sound
ReplyDelete