1

VF:

<apex:page standardController="Contact">
    <apex:form>
        <apex:pageBlock title="Edit Contact">
            <apex:pageBlockSection columns="1">
                <apex:inputField value="{!contact.FirstName}"/>
                <apex:inputField value="{!contact.LastName}"/>
                <apex:inputField value="{!contact.Email}"/>
            </apex:pageBlockSection>
            <apex:pageBlockButtons>
            <apex:commandButton action="{!save}" value="save"/>
                <apex:commandButton action="{!cancel}" value="cancel"/>
             </apex:pageBlockButtons>
            <apex:pageBlockTable value="{!conList}" var="c">
                <apex:column headerValue="First Name">
                <apex:outputField value="{!c.Firstname}" />
                </apex:column>
                <apex:column headerValue="Last Name">
                <apex:outputField value="{!c.Lastname}" />
                </apex:column>
                <apex:column headerValue="Email">
                <apex:outputField value="{!c.Email}" />
                </apex:column>
          </apex:pageBlockTable>
        </apex:pageBlock>
    </apex:form>
</apex:page>

Apex:

public with sharing class ContactEditController {
    public contact c {get; set;}
    public List<contact> conList {get;set;}
    public ContactEditController(){
        c= new Contact();   
    }
    public PageReference save(){
        insert c;
        conList= [select FirstName,LastName,Email from Contact where id=:c.id];
        return null;

    }
}
7

You are missing the extension in your VF page.

Your first line should be

<apex:page standardController="Contact" extensions="ContactEditController" />

However, unless you make a quick change to your controller, this won't work either. You have to implement a constructor (that the page will use)

public ContactEditController(ApexPages.StandardController stdController) {
  //Initialize your contact variable here
}

For more details, visit this page.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.