function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Hareesh SankaHareesh Sanka 

Create Sobject Account with Name,Industry,Phone and display in the VF page and save the record to Account object. Can anyone help on this code?

Raj VakatiRaj Vakati
Use this page
 
<apex:page standardController="Account">
  <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:inputField value="{!account.Name}"/>
        <apex:inputField value="{!account.Industry}"/>
        <apex:inputField value="{!account.Phone }"/>
      </apex:pageBlockSection>
    </apex:pageBlock>
  </apex:form>
</apex:page>

 
Hareesh SankaHareesh Sanka

Thanks Raj.
Can you please tell me how to write code without using Account as Standard Controller in VF page.(For example, declare the variables in apex class and display it in VF Page)

Raj VakatiRaj Vakati
Refer this code
 
public class MyController {

    private final Account account;

    public MyController() {
        account = [SELECT Id, Name, Industry,Phone  FROM Account 
                   WHERE Id = :ApexPages.currentPage().getParameters().get('id')];
    }

    public Account getAccount() {
        return account;
    }

    public PageReference save() {
        update account;
        return null;
    }
}
 
<apex:page controller="myController" tabStyle="Account">
    <apex:form>
        <apex:pageBlock title="Account Page">
           <apex:inputField value="{!account.Name}"/>
<apex:inputField value="{!account.Industry}"/> 
<apex:inputField value="{!account.Phone }"/> 
            <apex:commandButton action="{!save}" value="save"/>
        </apex:pageBlock>
    </apex:form>
</apex:page>