+ 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}" />
                 </apex:pageBlockSection>

 

Controller

 

public class DetailAc{
    public Account acc {get;set;}
   
    acc.Name=Account.Name;
           acc.AccountNumber=Account.AccountNumber;
                      acc.Owner=Account.Owner;

 

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

georggeorg

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"

georggeorg

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

 

Thanks,

George

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