Creating Account Record and get the data from server Using Standard Controllers and Extension in Salesforce Visualforce Page | how to call extension method in visualforce


Hey guys, today in this post we are going to learn about How to Create Account Record and get the data from server Using Standard Controllers and Extension in Salesforce Visualforce Page

Real time scenarios:- Create account record and get data using Visualforce Controller Extension.

Files we used in this post example

myVfpDemo.vfp Visualforce Page It use to access, display and update the data on webserver page.


Apex Class Controller It is used for create apex class method to retrieve the Account Details.

Live Demo

Get Data From Visualforce Controller Extension --


You can download file directly from github by Click Here.


Other related post that would you like to learn in Salesforce


Create Visualforce Page

Step 1:- Create Visualforce Page : myVfpDemo.vfp

From Developer Console >> File >> New >> Visualforce Page

myVfpDemo.vfp [Component Visualforce Page]

  1.   <apex:page standardController="Account" extensions="myVfpDemo">
  2.     <apex:form >
  3.        <apex:pageBlock >
  4.            <apex:pageBlockSection title="Create Account through Custom controller">
  5.                <apex:inputField label="Name" value="{!accObj.Name}"/>
  6.                <apex:inputField label="Phone" value="{!accObj.Phone}"/>
  7.                <apex:inputField label="Industry" value="{!accObj.Industry}"/>
  8.                <apex:inputField label="Rating" value="{!accObj.Rating}"/>
  9.                <apex:inputField label="Description" value="{!accObj.Description}"/>
  10.                <apex:inputField label="Website" value="{!accObj.Website}"/>
  11.            </apex:pageBlockSection>
  13.            <apex:pageBlockButtons >
  14.               <apex:commandButton value="save" action="{!createAccRecord}"></apex:commandButton>
  15.           </apex:pageBlockButtons>           
  16.        </apex:pageBlock>
  18.         <apex:pageBlock >
  19.             <apex:pageBlockSection title="List of Account">
  20.                 <apex:pageBlockTable value="{!accList}" var="accItem">
  21.                     <apex:column value="{!accItem.Name}"></apex:column>
  22.                     <apex:column value="{!accItem.Phone}"></apex:column>
  23.                      <apex:column value="{!accItem.Industry}"></apex:column>
  24.                      <apex:column value="{!accItem.Rating}"></apex:column>
  25.                      <apex:column value="{!accItem.Description}"></apex:column>
  26.                      <apex:column value="{!accItem.Website}"></apex:column>                     
  27.                 </apex:pageBlockTable>
  28.             </apex:pageBlockSection>
  29.         </apex:pageBlock>
  31.     </apex:form>
  32. </apex:page>

Create Apex Class Controller

Step 2:- Create Apex Class : myVfpDemo.apxc

From Developer Console >> File >> New >> Apex Class

myVfpDemo.apxc [Apex Class Controller]

  1.    public class myVfpDemo{    
  2.     public Account accObj{GET;SET;}
  3.     public List<Account> accList{GET;SET;}
  4.     public myVfpDemo(ApexPages.StandardController Controller){
  5.         accObj = NEW Account();
  6.         accList = NEW List<Account>();        
  7.         accList = [SELECT Id, Name, Phone, Industry, Rating, Description, Website FROM Account WHERE Phone !=NULL ];
  8.     }
  10.     public Pagereference createAccRecord(){
  11.         INSERT accObj;
  12.         RETURN NEW Pagereference('/'+ accObj.Id);
  13.     }
  15. }

Get Data From Visualforce Controller Extension --


Further post that would you like to learn in Salesforce




FAQ (Frequently Asked Questions)

What is standard controller in Visualforce page?

A Visualforce controller is a set of instructions that specify what happens when a user interacts with the components specified in associated Visualforce markup, such as when a user clicks a button or link.

Can we use custom controller and extension in one VF page?

We can't call multiple custom controllers on a VF Page, but we can call second controller while we have the first controller on VF page, and however you need to define your second controller as Extension rather as controller.

What is extension controller in Salesforce?

Controller extension in Salesforce is an Apex class containing a constructor that is used to add or extend the functionalities of a Standard Controller or custom controller in Salesforce. Extension controller is also used to leverage the functionality of another controller using our own custom logic.

Related Topics | You May Also Like

  • Our Free Courses β†’

Hi, This is Vijay Kumar behind the admin and founder of I am a senior software developer and working in MNC company from more than 8 years. I am great fan of technology, configuration, customization & development. Apart of this, I love to write about Blogging in spare time, Working on Mobile & Web application development, Salesforce lightning, Salesforce LWC and Salesforce Integration development in full time. [Read full bio] | | The Sitemap where you can find all published post on

Leave a Comment