+ Start a Discussion
maheshkovvadamaheshkovvada 

visualforce save button

I create save and cancel two buttons for the custom controller ..

   two methods for save and cancel and one constructor I created..

If u click save the record will save to database..

If I click save same page appearing

 

 

my question is : how to write save button coding to save the record in db.If u click save then save record..

Suresh RaghuramSuresh Raghuram

suppose you are passing values  into an account object

 

Account a = new Account(); // Create an instance for your object in which u want to save the record

Public pagereference saveRecord()

{

a.Name = InputName;

insert a;

}

Simply to save a record above is the process. If you have any questions provide the code sample you are doing so i can help you better.

 

If this answers your question click on solution for your question.

 

 

maheshkovvadamaheshkovvada

public class sampleCon {

    public PageReference Cancel() {
        return null;
    }
    Hardware_Requirements__c = new Hardware_Requirements__c();

    public String cancel { get; set; }

    public String Save { get; set; }

    public PageReference Save() {
    
        return null;
    }

public Hardware_Requirements__c HR{get;set;}
String country = null;
    public List<SelectOption> getItems() {
    List<SelectOption> options = new List<SelectOption>();
    options.add(new SelectOption('Free','Free'));
    options.add(new SelectOption('paid','paid'));
    return options;
    
}

 public samplecon()
 {
     HR = new Hardware_Requirements__c();
 }
 
public String getCountry()
    {
    return country;
    }
public void setCountry(String country)
    {
    this.country = country;
    }
    }

this is my code when i click save button it is not working and my obj is:Hardware Requirements

 

maheshkovvadamaheshkovvada

a.name = inputName;

what is name and inputName for

Suresh RaghuramSuresh Raghuram

Here a is the instance of the Account object and name is the fieldname of the account object and inputname is the

{! Input Name} (expression) which u give in vF Page as a Value="{! inputName}. More over make sure what is your  input field type is it a text box or picklist filed. If it is  a text field the one i said will be help full if not you need to make some changes.

SpandanaSpandana


How to Add Save & new buttons using visual force page

 

Visual FORCE PAGES


<apex:page standardController="Contact" extensions="LoginPages">
<apex:form >
<apex:sectionheader title="Contact Edit" subtitle="New Contact"/>

<apex:pageBlock title="Contact Edit" mode="edit">
<apex:pageBlockButtons >
<apex:commandButton value="Save" action="{!save}"/>
<apex:commandButton value="Cancel" action="{!cancel}"/>
<apex:commandButton value="Save & New" action="{!saveAndNew}"/>
</apex:pageBlock>

</apex:form>
</apex:page>


APEX CLASS

 

public class LoginPages {

public LoginPages(ApexPages.StandardController controller) {

}
public PageReference save() {
return null;
}
public PageReference saveAndNew() {
PageReference myfirstpage= new PageReference('/apex/myfirstpage');
myfirstpage.setRedirect(true);
return myfirstpage;
}
}