There are few ways to save records through custom page
1st method: use only standardController at the beginning of apex markup without using custom controller or extensions • inputField will be appeared as follow;
public status(ApexPages.StandardController stdController) {
this.applicant=(Applicant__c)stdController.getRecord();
}
public PageReference saveApplication() {
//IF you need more manupulation to your saving record, that code here
insert(applicant);
} }
3rd method: Use Standard controller with an extension and inputText • InputText
this is my vf page...... there is save button on each record,,,,so when record is edited and save is clicked records should be updated and page shoul be refreshed......
<apex:page controller="ContactGrid" id="thepage" > <apex:form id="theform" > <script> function saveorg() { alert('alert in save org '+document.getElementById("{!$Component.thepage.theform.theblock.thetable}").value); saverecord(document.getElementById("{!$Component.thepage.theform.theblock.thetable}").value); }
public class ContactGrid { public ContactGrid__c ContactGrid
public List<Contact> cppz{get;set;} public string retid{get;set;} public ContactGrid(ApexPages.StandardController controller) { ContactGrid__c ContactGrid= new ContactGrid__c(); }
public List<Contact> getCppz() { cppz=[Select c.Phone, c.LastName, c.FirstName, c.Email, c.AccountId From Contact c]; return cppz;
} public pageReference save() { Insert ContactGrid; return null;
public class ContactGrid
{
public ContactGrid__c ContactGrid
public List<Contact> cppz{get;set;}
public string retid{get;set;}
public ContactGrid(ApexPages.StandardController controller)
{
ContactGrid__c ContactGrid= new ContactGrid__c();
}
public List<Contact> getCppz()
{
cppz=[Select c.Phone, c.LastName, c.FirstName, c.Email, c.AccountId From Contact c];
return cppz;
}
public pageReference saveContact()
{
Insert cppz;
return null;
}
}
If a reply to a post answers your question or resolves your problem, please mark it as the solution to the post so that others may benefit.
There are few ways to save records through custom page
1st method: use only standardController at the beginning of apex markup without using
custom controller or extensions
• inputField will be appeared as follow;
2nd method: Use Standard controller with an extension
• inputField
• commandButton
• custom controller must have below methods
3rd method: Use Standard controller with an extension and inputText
• InputText
• ComandButton (no chnage)
• Custom Controller must have following property
• Following code will appear in saveApplication method
If a reply to a post answers your question or resolves your problem, please mark it as the solution to the post so that others may benefit.
HI
Try this
<apex:page controller="book" >
<apex:form >
<apex:pageBlock title="Book Details">
<apex:pageBlockSection title="Books" columns="2" >
<apex:inputField value="{!book.Title__c}" label="Title"/>
<apex:inputField value="{!book.Author__c}" label="Author"/>
<apex:inputField value="{!book.Price__c}" label="Price"/>
<apex:inputField value="{!book.Publisher__c}" label="Publisher"/>
</apex:pageBlockSection>
<apex:pageBlockButtons location="top">
<apex:commandButton value="save" action="{!save}"/>
</apex:pageBlockButtons>
</apex:pageBlock>
</apex:form >
</apex:page>
Now controller is
public class book {
public Book__c book;
public book(){
Book__c book = new Book__c();
}
public pageReference save(){
upsert/Insert book;
reyurn null;
}
}
Did this post answers your issue If so please mark it solved
thanks
asish
this is my vf page...... there is save button on each record,,,,so when record is edited and save is clicked records should be updated and page shoul be refreshed......
<apex:page controller="ContactGrid" id="thepage" >
<apex:form id="theform" >
<script>
function saveorg()
{
alert('alert in save org '+document.getElementById("{!$Component.thepage.theform.theblock.thetable}").value);
saverecord(document.getElementById("{!$Component.thepage.theform.theblock.thetable}").value);
}
</script>
<apex:pageBlock title="Contact Grid" id="theblock" >
<apex:commandButton value="Create New Button"/>
<apex:pageBlockTable width="80%" columns="6" value="{!cppz}" var="o" id="thetable">
<apex:column headerValue="Action" >
<apex:commandButton value="Save" id="savebutton"/>
</apex:column>
<apex:column headerValue="Last Name" >
<apex:inputField value="{!o.LastName}"/>
</apex:column>
<apex:column headerValue="First Name" >
<apex:inputField value="{!o.FirstName}"/>
</apex:column>
<apex:column headerValue="Email" >
<apex:inputField value="{!o.Email}"/>
</apex:column>
<apex:column headerValue="Phone">
<apex:inputField value="{!o.Phone}"/>
</apex:column>
<apex:column headerValue="Account Name" >
<apex:inputField value="{!o.AccountId }"/>
</apex:column>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:form>
</apex:page>
this my class....
public class ContactGrid
{
public ContactGrid__c ContactGrid
public List<Contact> cppz{get;set;}
public string retid{get;set;}
public ContactGrid(ApexPages.StandardController controller)
{
ContactGrid__c ContactGrid= new ContactGrid__c();
}
public List<Contact> getCppz()
{
cppz=[Select c.Phone, c.LastName, c.FirstName, c.Email, c.AccountId From Contact c];
return cppz;
}
public pageReference save()
{
Insert ContactGrid;
return null;
}
}
Hi
Try this
public Id yourpageid{get;set;}
public pageReference save()
{
upsert ContactGrid;
yourpageid = ApexPages.currentPage().getParameters().get('optId');
PageReference samepage=new PageReference('/apex/yourpagename?id='+yourpageid);
samepage.setRedirect(true);
return samepage;
}
Did this post answers your question If so please mark it solved.
Thanks
asish
Do following highlighted changes
If a reply to a post answers your question or resolves your problem, please mark it as the solution to the post so that others may benefit.
HI Chamil,
IT DOESN'T WORK....ACTUALLY input fields are editable ..so when do i change them and click save ..changes should be saved..
After the save, you need to render outputfields.
If a reply to a post answers your question or resolves your problem, please mark it as the solution to the post so that others may benefit.
donot works:On being click on save it returns to the same page without saving the changes,,
public class ContactGrid
{
public Boolean Displayout{get;set;}
public List<Contact> con{get;set;}
public List<Contact> cppz;
public Id retid{get;set;}
public ContactGrid(){}
public List<Contact> getCppz()
{
cppz=[Select c.Phone, c.LastName, c.FirstName, c.Email, c.AccountId From Contact c];
return cppz;
}
public pageReference saveContact()
{
upsert cppz;
Displayout = true;
return null;
}
}
vf page
<apex:page controller="ContactGrid" id="thepage" >
<apex:form id="theform" >
<apex:pageBlock title="Contact Grid" id="theblock" >
<apex:commandButton value="Create New Button"/>
<apex:pageBlockTable width="80%" columns="6" value="{!cppz}" var="o" id="thetable">
<apex:column headerValue="Action" >
<apex:commandButton value="Save" id="savebutton" action="{!saveContact}" rendered="{!Displayout == false}"/>
</apex:column>
<apex:column headerValue="Last Name" >
<apex:inputField value="{!o.LastName}" rendered="{!Displayout == false}"/>
</apex:column>
<apex:column headerValue="First Name" >
<apex:inputField value="{!o.FirstName}" rendered="{!Displayout == false}"/>
</apex:column>
<apex:column headerValue="Email" >
<apex:inputField value="{!o.Email}" rendered="{!Displayout == false}"/>
</apex:column>
<apex:column headerValue="Phone">
<apex:inputField value="{!o.Phone}" rendered="{!Displayout == false}"/>
</apex:column>
<apex:column headerValue="Account Name" >
<apex:inputField value="{!o.AccountId }" rendered="{!Displayout == false}"/>
</apex:column>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:form>
</apex:page>