You need to sign in to do that
Don't have an account?
mr209204
Saving
What I'm trying to do is save information from a form. Everything I have done is based off examples from SF Docs like the Cookbook so forgive me if things look a little haphazard. This is the code that I have so far. I know that I have to Include <apex:commandButton action="{!save}"> somewhere in there and that I have to create a method for it. This is where I am stuck. I don't quite understand the examples given to me in the cookbook or the visual force documentation. Here is the apex that I have so far. How do I go about saving all this information once entered?
So what would I have to add on the controller side?
Message Edited by mr209204 on 07-21-2008 02:23 PM
<apex:page Controller="testController" tabStyle="Contact">
<apex:sectionHeader title="Create new Contact" />
<apex:form >
<apex:pageBlock title="Contact" id="thePageBlock" mode="edit">
<apex:pageMessages />
<apex:pageBlockButtons >
</apex:pageBlockButtons>
<apex:actionRegion >
<apex:pageBlockSection title="Contact Information" columns="1">
<apex:inputField value="{!contact.firstName}"/>
<apex:inputField value="{!contact.lastName}"/>
<apex:inputField value="{!contact.MailingStreet}"/>
<apex:inputField value="{!contact.MailingCity}"/>
<apex:inputField value="{!contact.MailingState}"/>
<apex:inputField value="{!contact.MailingPostalCode}"/>
<apex:inputField value="{!contact.HomePhone}" />
<apex:inputField value="{!contact.MobilePhone}" />
<apex:inputField value="{!contact.Fax}" />
<apex:pageBlockSectionItem >
<apex:outputLabel value="Add Company"/>
<apex:outputPanel >
<apex:inputField value="{!contact.Add_Company__c}">
<apex:actionSupport event="onchange" rerender="thePageBlock"status="status2"/>
</apex:inputField>
<apex:actionStatus startText="applying value..." id="status2"/>
</apex:outputPanel>
</apex:pageBlockSectionItem>
</apex:pageBlockSection>
</apex:actionRegion>
<apex:pageBlockSection title="Company Information" columns="1"
rendered="{!contact.Add_Company__c == true}">
<apex:inputField value="{!account.name}" />
<apex:inputField value="{!account.BillingStreet}" />
<apex:inputField value="{!account.BillingCity}" />
<apex:inputField value="{!account.BillingState}" />
<apex:inputField value="{!account.BillingPostalCode}" />
<apex:inputField value="{!account.Phone}" />
<apex:inputField value="{!account.Fax}" />
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
Message Edited by mr209204 on 07-21-2008 02:23 PM
Your controller has to have a save() method. Assuming you're working on the example where you create an Account, Opportunity, and Contact in one fell swoop, it should look something like this:
Note that the signature of the save method (or any other method that you invoke from a VisualForce page) can't include any arguments. When you invoke the save method from your VisualForce code, you don't even use parentheses -- that is, you invoke it with {!save} and NOT {!save()}. (Figuring that out cost me a few hours....)
I hope this helps!
Jeri