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
Gaurav RajGaurav Raj 

Rectify the error in the code

public class customAccountController{
    public Account ac {get;set;}
   
    Id accId = apexpages.currentpage().getparameters().get('id');

 

  Account acc = [select Name,AccountNumber, Site,NumberOfEmployees,Fax,Ownership,Industry from account where id=:accid];

 


}

sfdcfoxsfdcfox
What error are you getting? What's wrong? This code looks perfectly fine.
Gaurav RajGaurav Raj

VF page:

 

<apex:page showHeader="false" controller="customAccountController" title="My Account" >
   
    <div class="panel" id="acctDetail" selected="true" style="padding: 10px;
      margin-top:-44px" title="Account Information" >
       <h2>{!Account.Name}</h2>

       <fieldset style="margin: 0 0 20px 0;">

          <div class="row">
             <label>Phone:</label>
             <input type="text" value="{!Account.Phone}" />
          </div>

          <div class="row">
             <label>Rating:</label>
             <input type="text" value="{!Account.Rating}" />
          </div>

       </fieldset>

    </div>

</apex:page>

 

controller:

 

 

sfdcfoxsfdcfox
<apex:page showHeader="false" standardController="Account" title="My Account">
   
    <div class="panel" id="acctDetail" selected="true" style="padding: 10px;
      margin-top:-44px" title="Account Information" >
       <h2>{!Account.Name}</h2>

       <fieldset style="margin: 0 0 20px 0;">

          <div class="row">
             <label>Phone:</label>
             <input type="text" value="{!Account.Phone}" />
          </div>

          <div class="row">
             <label>Rating:</label>
             <input type="text" value="{!Account.Rating}" />
          </div>

       </fieldset>

    </div>

</apex:page>

 

 

You were trying to access "Account" instead of "ac", but you didn't actually need the custom controller at all-- a standard controller is just fine here. You can use an "extension" if you need to add custom logic beyond querying basic data or saving the record.

Gaurav RajGaurav Raj

Hiow to go about writing its extension?

sfdcfoxsfdcfox

No extension is needed for this particular piece of code. You would use an extension to add functions not already available in Visualforce.

 

The extension would start of as:

 

public with sharing class someExtension {
    ApexPages.StandardController controller;
    public someExtension(ApexPages.StandardController controller) {
        this.controller = controller;
    }
}