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
Nishad BashaNishad Basha 

How to retrieve the Account data in visualforce page using components?

NagaNaga (Salesforce Developers) 
Hi Nishad,

Please see the example below

User-added image
Please see the link below

https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_quick_start_iteration_components.htm

Best Regards
Naga kiran
ADITYA PRAKASH 5ADITYA PRAKASH 5
Hi Nishad,

You can use standard Controller in your page to retrive the Account data in visualforce page using components. 
Eg:

<apex:page standardController="Account">
    <apex:outputField value="{!Account.name}"/>
    <apex:outputField value="{!Account.name}"/>
 </apex:page>
Himanshu ParasharHimanshu Parashar
Hi Nishad,

You need to create a component which will receive Account id as parameter and then extract other field inside the component.

so your visualforce page will be like this

 
<c:AccountDetails Accountid="{!Account.id}"/>



your component will look like this.
 
<apex:component controller="AccountExtension"> 
<apex:attribute name="Accountid" type="String" description="Account page" assignTo="{!Accid}" required="true"/>

//Your other Account fields here.

</apex:component>


and here will be your apex class
 
public class AccountExtension {
    public Account acc;
    public String Accid;
    public String getAccid(){return Accid;}
      
    public void setAccid(String userinput)
    {
       //Your logic here to get data and display in visualfoce component.
    }  

    public ContactListExtension() {
    }    
    
    
}


Makes sense?

Thanks,
Himanshu
 
Nishad BashaNishad Basha
Hi, Himanshu
can you please send above scenario complete code.
Himanshu ParasharHimanshu Parashar
Hi Nishad,

That is complete code you need to only query Account object in Accountextension class at line 8
Himanshu ParasharHimanshu Parashar
   public void setAccid(String userinput)
   {
       //Your logic here to get data and display in visualfoce component.
       acc = [select id,Name from Account where id =: userinput];

    }

component
 
<apex:component controller="AccountExtension"> 
<apex:attribute name="Accountid" type="String" description="Account page" assignTo="{!Accid}" required="true"/>

<apex:outputfield value="{!acc.Name}"/>

</apex:component>