Activity › Forums › Salesforce® Discussions › How to use vf page of custom controller in sobject page?
-
How to use vf page of custom controller in sobject page?
Posted by PRANAV on August 8, 2016 at 1:44 PMHi All,
How to use vf page of custom controller in sobject page?
Thanks
Saurabh replied 9 years, 1 month ago 2 Members · 1 Reply -
1 Reply
-
Hi Pranav,
If i am not wrong i think you want to create an sobject page replica by using custom controller.
you can try this:
#vf page for making sobject account with field accountname:
<apex:page controller=”myController” >
<apex:form >
<apex:pageBlock title=”My Content” mode=”edit”>
<apex:pageBlockButtons >
<apex:commandButton action=”{!save}” value=”Save”/>
</apex:pageBlockButtons>
<apex:pageBlockSection title=”My Content Section”
columns=”2”>
<apex:outputLabel for=”aName”>Account Name:</
apex:outputLabel>
<apex:inputText value=”{!accountName}”/>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>#And the controller class for this:
public with sharing class myController {
private final Id accountId ;
public final String accountName {get; set; }public myController() {
Account account = [select Id, Name from Account where id
= :ApexPages.currentPage().getParameters().get(‘id’)];
accountId = account.Id ;
accountName = account.Name ;
}public PageReference save() {
Account myAccount = [select name from Account where id
= :accountId];
myAccount.name = accountName ;
update myAccount;
return null;
}
}Similarly you can add more fields as you wanted by adding components in vf page and creating functions in controller class.
Hoping this is the solution for you question:
Thanks
Log In to reply.