+ Start a Discussion
Gaurav RajGaurav Raj 

Help with the code

Am trying to fetch all the fields and its values of Account object on a vf page


here is the piece of code i have written


pex:page controller="DetailAc" tabStyle="Account">
     <apex:pageBlockSection columns="2">
                    <apex:outputField value="{!acc.Name}"/>
                    <apex:outputField value="{!acc.AccountNumber}"/>
                    <apex:outputField value="{!acc.Owner}"/>
                    <apex:outputField value="{!acc.Site}" />
                    <apex:outputField value="{!acc.NumberOfEmployees}" />
                    <apex:outputField value="{!acc.Fax}" />
                    <apex:outputField value="{!acc.Ownership}" />
                    <apex:outputField value="{!acc.ShippingAddress}" />
                    <apex:outputField value="{!acc.Type}"/>
                    <apex:outputField value="{!acc.Industry}" />




public class DetailAc{
    public Account acc {get;set;}


Help me with the code. Also i need to pass the id dynamically.


i hope you might be passing id in the url.


Use the following code in the controller 


Id accId = apexpages.currentpage().getparameters().get('id');


acc = [select Name,AccountNumber, Site,NumberOfEmployees,FaxOwnership,ShippingAddress,Type,Industry from account where id=:accid];


The above query dynamically set the acc variable.


Hope this helps:-)


Gaurav RajGaurav Raj

The following line is throwing an error:


<apex:page controller="DetailAc"  tabStyle="Account">


error is: UnknownProperty "DetailAc.acc"


and the following line in the controller also throws an error:


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


error is: Unexpected Token "acc"


Check whethere you have defined an account variable  named acc  in your controller. If you are unable to resolve please post the complete code - controller,page.


I can help you




Gaurav RajGaurav Raj

<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" >

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

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

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