• #15030
    Salesforce | PRANAV PRANAV #2
    Forcetalks

    How to use vf page of custom controller in sobject page?

    Hi All,

    How to use vf page of custom controller in sobject page?

    Thanks

    Tagged: , , ,

    #18648
    Salesforce | Saurabh Saurabh #24
    Forcetalks

    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

Viewing 2 posts - 1 through 2 (of 2 total)

Please to reply to this topic.

CONTACT US

We're not around right now. But you can send us an email and we'll get back to you, asap.

Sending

About Us

Forcetalks is a Salesforce collaboration platform for coders & developers, geeks & nerds, consultants & business heads, admins & architects, managers & marketers and of course the business owners. A community where you can learn from, where you can contribute to. For you. For Salesforce. Read More...

Copyright 2018 Forcetalks. All Right Reserved.

Log in with your credentials

or    

Forgot your details?