Activity Forums Salesforce® Discussions How to use vf page of custom controller in sobject page?

  • Saurabh

    Member
    March 24, 2017 at 7:38 am

    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&nbsp;;
    public final String accountName {get; set; }

    public myController() {
    Account account = [select Id, Name from Account where id
    =&nbsp;:ApexPages.currentPage().getParameters().get(‘id’)];
    accountId = account.Id&nbsp;;
    accountName = account.Name&nbsp;;
    }

    public PageReference save() {
    Account myAccount = [select name from Account where id
    =&nbsp;:accountId];
    myAccount.name = accountName&nbsp;;
    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.

Popular Salesforce Blogs

Popular Salesforce Videos