You need to sign in to do that
Don't have an account?
Save in Custom Controller
I`m creating a visualforce page and want to know how i use SAVE action in the controller code?
The code in VFP is:
<apex:page controller="EAccount">
<apex:form >
<apex:pageBlock title="NEW Email Account">
<apex:pageblockButtons location="Bottom" >
<apex:commandButton action="{!Save}" value="Create Account" />
</apex:pageblockButtons>
<apex:pageBlockSection columns="1" title="Enter Information">
<apex:inputField value="{!ema.First_Name__c}"/>
<apex:inputField value="{!ema.Last_Name__c}"/>
<apex:inputField value="{!ema.Username__c}"/>
<apex:inputSecret value="{!ema.Password__c}" label="Password"/>
<apex:inputField value="{!ema.Mobile__c}"/>
<apex:inputField value="{!ema.Birthday__c}"/>
<apex:inputField value="{!ema.Male__c}" label="Male"/>
<apex:inputField value="{!ema.Female__c}" label="Female"/>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
Controller Class
public class EAccount {
public static void LoginPage(){
}
public Email_Account__c ema{get; set;}
public String EmailAccount { get; set; }
public PageReference Save() {
return null;
PageReference LoginPage = Page.MyLoginPage;
LoginPage.setRedirect(true);
return LoginPage;
}
}
An error occurs an is not saving the records.
However, if you are sure you need to have a custom controller, you need to instantiate a new record in the constructor:
and then insert this in the save method. Also, you have two return statements in your save method so I'm surprised it compiles. I'm assuming that you want to send the user to the login page:
I'm also not sure what the point of the public static void loginPage method is...