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. |
myVfpDemo.apxc |
Apex Class Controller | It is used for create apex class method to retrieve the Account Details. |
Live Demo
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]
|
<apex:page standardController="Account" extensions="myVfpDemo">
<apex:form >
<apex:pageBlock >
<apex:pageBlockSection title="Create Account through Custom controller">
<apex:inputField label="Name" value="{!accObj.Name}"/>
<apex:inputField label="Phone" value="{!accObj.Phone}"/>
<apex:inputField label="Industry" value="{!accObj.Industry}"/>
<apex:inputField label="Rating" value="{!accObj.Rating}"/>
<apex:inputField label="Description" value="{!accObj.Description}"/>
<apex:inputField label="Website" value="{!accObj.Website}"/>
</apex:pageBlockSection>
<apex:pageBlockButtons >
<apex:commandButton value="save" action="{!createAccRecord}"></apex:commandButton>
</apex:pageBlockButtons>
</apex:pageBlock>
<apex:pageBlock >
<apex:pageBlockSection title="List of Account">
<apex:pageBlockTable value="{!accList}" var="accItem">
<apex:column value="{!accItem.Name}"></apex:column>
<apex:column value="{!accItem.Phone}"></apex:column>
<apex:column value="{!accItem.Industry}"></apex:column>
<apex:column value="{!accItem.Rating}"></apex:column>
<apex:column value="{!accItem.Description}"></apex:column>
<apex:column value="{!accItem.Website}"></apex:column>
</apex:pageBlockTable>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</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]
|
public class myVfpDemo{
public Account accObj{GET;SET;}
public List<Account> accList{GET;SET;}
public myVfpDemo(ApexPages.StandardController Controller){
accObj = NEW Account();
accList = NEW List<Account>();
accList = [SELECT Id, Name, Phone, Industry, Rating, Description, Website FROM Account WHERE Phone !=NULL ];
}
public Pagereference createAccRecord(){
INSERT accObj;
RETURN NEW Pagereference('/'+ accObj.Id);
}
}
Further post that would you like to learn in Salesforce
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 β
π Get Free Course β
π Salesforce Administrators π Salesforce Lightning Flow Builder π Salesforce Record Trigger Flow Builder |
π Get Free Course β
π Aura Lightning Framework π Lightning Web Component (LWC) π Rest APIs Integration |