You need to sign in to do that
Don't have an account?
how to insert records to customtable using purly customController
hi mates please help in below Scenario;
Scenario: i have visual page consists of three feilds name,price,address and save button. when i click on save button these fileds information must be stored as record in custom tableor object Book1__c .
please provide code for this Scenario.
I have tried with some smple code but its not working am new to apex Language;
public class Book3
{
string name=null;
Double Bookprice=null;
Integer Bookid=null;
public Book1__c newbook;
public Book3()
{
ID id=ApexPages.CurrentPage().getParameters().get('id');
newbook = (id == null)?new Book1__c():
[select Bookid__c,name,Bookprice__c from Book1__c where id=:id];
}
public String getName()
{
return name;
}
public void setName(String name)
{
this.name=name;
}
public Integer getNumber()
{
return Bookid;
}
public void setNumber(Integer Bookid)
{
this.Bookid=Bookid;
}
public Double getprice()
{
return Bookprice;
}
public void setprice(Double Bookprice)
{
this.Bookprice=Bookprice;
}
public Book1__c getbook()
{
return newbook;
}
public pageReference save()
{
try{
upsert newbook;
}
catch(System.DmlException e)
{
ApexPages.addMessages(e);
return null;
}
return null;
}
}
visual page
-----------
<apex:page controller="Book3">
<apex:form >
<apex:pageBlock title="This is sample" mode="edit">
<apex:pageMessages />
NAME:
<apex:inputText value="{!Name}"/>
<br/>
BOOKID:
<apex:inputText value="{!Number}"/>
<apex:commandButton value="save" action="{!save}"/>
</apex:pageBlock>
</apex:form>
</apex:page>
That usually means there's a character or two before the <apex:page> tag.
All Answers
Rather than maintaining the values as attributes of the controller, you should be able to simply use the newbook instance for most of this:
and on the page:
it displaying following error.
Error Error: Author4 line 1, column 1: Content is not allowed in prolog Error Error: Content is not allowed in prolog.
1 <apex:page controller="Book3">
2 <apex:form >
3 <apex:pageBlock title="This is sample" mode="edit">
4 <apex:pageMessages />
5 NAME:
6 <apex:inputField value="{!book.Name}"/>
7 <br/>
8 BOOKID:
9 <apex:inputField value="{!book.Bookid__c}"/>
10 <apex:commandButton value="save" action="{!save}"/>
11 </apex:pageBlock>
12 </apex:form>
13 </apex:page>
That usually means there's a character or two before the <apex:page> tag.