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
Chidanand MChidanand M 

controller.getRecord();

Hello, friends
public Account ac{get;set;}

ac= (Account)controller.getRecord();
And
ac= new Account();

Are these both declaration produce the same difference??
I am getting the correct output for both the declaration?
Which one is correct??
Can anyone clear my doubt? M bit confused..

Visualforce

<apex:inputField value="{!ac.Site}"/>
 <apex:inputField value="{!ac.Description}"/>
 <apex:inputField value="{!ac.Name}"/>


 
Jefferson  EscobarJefferson Escobar
ac= (Account)controller.getRecord(); //Get a record declare as standard controller, in such case an account record and its Id pass by URL. Use a StandardController when defining an extension for a standard controller.

ac= new Account(); // Get a new sobject instance of account.

Visualforce:
<apex:page standardController="Account" extension="myController" >
<apex:inputField value="{!ac.Site}"/>
 <apex:inputField value="{!ac.Description}"/>
 <apex:inputField value="{!ac.Name}"/>

Both are corrected, depends on your needs. If you define as standardController in the visualforce page, then user controller.getRecord(); thefore you will take advantage of capturing parameters of the page as the id or other value stated on it.