Here in stud Sobject there are two master_deatils i.e course and trainer name. I need to insert the data. But not able to insert.Please help me...Thaks In Advance..
<apex:page controller="insert_cc_Class">
<apex:form >
<apex:pageBlock >
<apex:pageBlockButtons >
<apex:commandButton value="SAVE" action="{!save}"/>
<apex:commandButton value="CANCEL" action="{!cancel}"/>
</apex:pageBlockButtons>
<apex:pageBlockSection title="Student Details">
<apex:pageBlockSectionItem >
<apex:outputLabel value="Student Name"/>
<apex:inputText value="{!Sname}" />
</apex:pageBlockSectionItem><br/>
<apex:pageBlockSectionItem >
<apex:outputLabel value="Contact Number"/>
<apex:inputText value="{!Snumber}"/>
</apex:pageBlockSectionItem><br/>
<apex:pageBlockSectionItem >
<apex:outputLabel value="Course Name"/>
<apex:inputText value="{!SCourseName}" />
</apex:pageBlockSectionItem><br/>
<apex:pageBlockSectionItem >
<apex:outputLabel value="Trainer Name"/>
<apex:inputText value="{!trainername}"/>
</apex:pageBlockSectionItem><br/>
<apex:pageBlockSectionItem >
<apex:outputLabel value="Date Of Birth"/>
<apex:inputText value="{!dob}"/>
</apex:pageBlockSectionItem><br/>
<apex:pageBlockSectionItem >
<apex:outputLabel value="Qualification"/>
<apex:selectList size="1">
<apex:selectOption itemValue="B-Tech" />
<apex:selectOption itemValue="Diploma" />
<apex:selectOption itemValue="Graduate" />
<apex:selectOption itemValue="MBA" />
<apex:selectOption itemValue="MCA" />
<apex:selectOption itemValue="PG" />
<apex:selectOption itemValue="PHD" />
<apex:selectOption itemValue="Under Graduate" />
</apex:selectList>
</apex:pageBlockSectionItem><br/>
<apex:pageBlockSectionItem >
<apex:outputLabel value="State"/>
<apex:inputText value="{!state}"/>
</apex:pageBlockSectionItem><br/>
<apex:pageBlockSectionItem >
<apex:outputLabel value="City"/>
<apex:inputText value="{!city}"/>
</apex:pageBlockSectionItem>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
public class insert_cc_Class {
// private ApexPages.StandardController controller;
public String city { get; set; }
public String state { get; set; }
public String qualification { get; set; }
public integer dob { get; set; }
public String trainername { get; set; }
public String SCourseName { get; set; }
public integer Snumber { get; set; }
public String Sname { get; set; }
public PageReference cancel() {
return null;
}
public PageReference save() {
Stud__C obj = new Stud__C();
obj.Sname__c = Sname;
obj.Contact_Number__c = String.valueOf(Snumber);
obj.Qualification__c = qualification;
obj.DOB__c = date.ValueOf(dob);
obj.Course_Name__c = SCourseName;
obj.Trainer_Name__c = trainername;
obj.State__c = state;
obj.City__c = city;
Insert obj;
return null;
}
}
this is very complicated way to do it. Do you really need all these "outputLabel, inputText" etc? It's simpler if you use apex:inputField (it'd magically know the field label and whether the field type is text/date/picklist) and it'd let you easily display lookups too.
There are rare situations when you can't do that (need to bypass SF profile field permissions) but it's in "I really know what I'm doing" category. And for these if you can't just display a lookup you need to hand-craft some search + autocomplete solution. There should be lots of examples on net how to create VF+apex search by name functionality.
That's really reiinventing the wheel though. Seriously, consider using <apex:inputField>
public class Stack72386167{
public Contact con {get;set;}
public Stack72386167(){
con = new Contact();
}
public void save(){
insert con;
}
}
<apex:page controller="Stack72386167">
<apex:form>
<apex:pageBlock>
<apex:pageBlockButtons>
<apex:commandButton value="Save" action="{!save}" />
</apex:pageBlockButtons>
<apex:pageBlockSection columns="1">
<apex:inputField value="{!con.Salutation}" /> <!-- picklists -->
<apex:inputField value="{!con.FirstName}" />
<apex:inputField value="{!con.LastName}" />
<apex:inputField value="{!con.AccountId}" /> <!-- lookups
<apex:inputField value="{!con.Birthdate}" /> <!-- dates (and of course right field labels picked for "free", admin can change them without code changes -->
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
Related
when i update my existing data with visualforce page , i got thi error
Update failed. First exception on row 0; first error: MISSING_ARGUMENT, Id not specified in an update call: []
Error is in expression '{!edit}' in page contract_object: Class.ContractController.edit: line 28, column 1
An unexpected error has occurred. Your development organization has been notified.
please complite my code without error
My Visual force Code is
<apex:page Controller="ContractController" sidebar="false" showHeader="false">
<apex:form >
<apex:pageBlock title="Contract Form">
<apex:pageBlockSection >
<apex:selectList size="1">
<apex:selectOptions value="{!contactlist}">
</apex:selectOptions>
</apex:selectList>
</apex:pageBlockSection>
<apex:pageBlockSection columns="1">
<apex:inputField value="{!conObj.Name}" />
<apex:inputField value="{!conObj.First_Name__c}" />
<apex:inputField value="{!conObj.Last_Name__c}" />
<apex:inputField value="{!conObj.Phone_Number__c}" />
<apex:inputField value="{!conObj.Address__c}" />
<apex:inputField value="{!conObj.Email__c}" />
</apex:pageBlockSection>
<apex:pageBlockButtons location="bottom">
<apex:commandButton value="Save" action="{!save}"/>
<apex:commandLink value="Edit" action="{!edit}"/>
</apex:pageBlockButtons>
</apex:pageBlock>
</apex:form>
</apex:page>
my controller code
public class ContractController {
public List<Contract__c> ContractTemp = new List<Contract__c>();
public List<SelectOption> contactlist
{
get
{
ContractTemp = [Select Id,Name from contract__c];
contactlist = new List<SelectOption>();
for(Contract__c con : ContractTemp)
{
contactlist.add(new SelectOption(con.Id, con.Name));
}
return contactlist;
}
set;
}
public ContractController() {
conObj = new Contract__c();
}
public Contract__c conObj {get; set;}
public void save() {
insert conObj;
}
public void edit() {
update conObj;
}
}
I have 2 wrapper class as below
public class Wr_Studennt{
public string name{get;set;}
public decimal salary{get;set;}
public decimal exp{get;set;}
public string technology{get;set;}
}
public class Wr_Address {
public String city{get;set;}
public string place{get;set;}
public string pincode{get;set;}
public String state{get;set;}
}
I have apex class as below
public class wr_Student_Address {
public Wr_Studennt st{set;get;}
public wr_student_Address()
{
st=new Wr_Studennt();
}
public void setstudent(string name,decimal salary,decimal exp,string technology)
{
st.name=name;
st.salary=salary;
st.exp=exp;
st.technology=technology;
}
}
My VF page isas below
<apex:page controller="wr_Student_Address">
<apex:form>
<apex:pageblock title="Student Details">
<apex:pageBlockSection>
<apex:outputLabel value="Name: "/>
<apex:inputText value="{!name}" />
<apex:outputLabel value="Salary: "/>
<apex:inputText value="{!salary}" />
<apex:outputLabel value="Exp: "/>
<apex:inputText value="{!exp}" />
<apex:outputLabel value="Technology: "/>
<apex:inputText value="{!technology}" />
<apex:commandButton value="setstudent" action="{! setstudent}" />
</apex:pageBlockSection>
</apex:pageblock>
</apex:form>
</apex:page>
It shows
Unknown property 'wr_Student_Address.name' error in line 0.
Please help me solving this issue.
visualforce page shows
unknown method error
Your page controller wr_Student_Address has only 1 property: st. There's no field called name directly in this class.
Try with merge field {!st.name}
want to display text in filed based onclick of checkbox in VF page.but the same checkbox is calling one method.
code is bellow....please write controller. need urget help..
<apex:outputPanel id="jobPanel">
Try the code below
Apex Class:
public class Test
{
public Boolean isChecked { get; set; }
public String myText{get;set;}
public void controllerMethod()
{
myText = 'Your Text field rendered';
//assign text field values
}
}
Visualforce Page:
<apex:page controller="Test" >
<apex:form >
<apex:pageBlock id="jobBlock">
<apex:inputCheckbox id="inche" value="{!isChecked}" >
<apex:actionsupport event="onclick" action="{!controllerMethod}" rerender="jobPanel" />
</apex:inputCheckbox>
<apex:outputPanel id="jobPanel">
<apex:pageBlockSection rendered="{!isChecked}">
<apex:pageblockSectionItem >
<apex:inputText value="{!myText}"/>
</apex:pageblockSectionItem>
</apex:pageBlockSection>
</apex:outputPanel>
</apex:pageBlock>
</apex:form>
</apex:page>
Hope it helps you
I am trying to refresh a page block section based on the value of a select list. Here is the VF:
<apex:pageblockSectionItem >
<apex:selectList size="1" value="{!reasonCode}">
<apex:selectOptions value="{!reasonCodes}"/>
<apex:actionSupport event="onchange" reRender="a"/>
<apex:actionSupport event="oncomplete" action="{!isAcceptedReasonCode}" reRender="orders"/>
</apex:selectList>
</apex:pageblockSectionItem>
</apex:pageBlockSection>
<apex:pageBlockSection id="orders" rendered="{!isAcceptedRC==true}" >
<apex:outputLabel value="Order Number" for="odNum"/>
<apex:inputText id="odNum" value="{!OrderNumber}"/>
</apex:pageBlockSection>
I have tried a bunch of different events, but none seem to work. Here is the isAcceptedReasonCode function:
public PageReference isAcceptedReasonCode (){
if(reasonCode == 'Accepted Offer') {
isAcceptedRC = true;
}else {
isAcceptedRC = false;
}
return null;
}
This seems pretty straightforward but it doesn't seem to work... of course i change the select list to be = 'Accepted Offer'
Add apex:outputPanel above apex:pageBlockSection and reRender outputpanel when Selection options is changed.
Sample Code:
<apex:pageblockSectionItem >
<apex:selectList size="1" value="{!reasonCode}">
<apex:selectOption itemLabel="Test" itemValue="Test"></apex:selectOption>
<apex:selectOption itemLabel="Accepted Offer" itemValue="Accepted Offer"></apex:selectOption>
<apex:actionSupport event="onchange" action="{!isAcceptedReasonCode}" reRender="testPanel"/>
</apex:selectList>
</apex:pageblockSectionItem >
</apex:pageBlockSection>
<apex:outputPanel id="testPanel">
<apex:pageBlockSection id="orders" rendered="{!isAcceptedRC}" >
<apex:outputLabel value="Order Number" for="odNum"/>
<apex:inputText id="odNum" value="{!OrderNumber}"/>
</apex:pageBlockSection>
</apex:outputPanel>
</apex:pageBlock >
When I use the standard save action in the commandButton it goes every time to the default page.
But I want to chamge to a custom page when i click on the save button..how??
I tried a lot of things like this...
public Pagereference goHome(){
Pagereference to = Apexpages.currentPage();
to.setRedirect(true);
return to;
}
or
public Pagereference goHome(){
Pagereference to = new Pagereference('/apex/mypage?user=guest'); return to;
}
<apex:commandButton value="Save" action="{!goHome}" />
It should be very simple! Check how this example works for you (you'll need to associate the page to a valid Opportunity by adding ?id=006... in the URL).
public class redirectTestCtrl{
public Opportunity o {get;set;}
public redirectTestCtrl(ApexPages.StandardController ctrl){
o = (Opportunity)ctrl.getRecord();
}
public PageReference save(){
upsert o;
//return new PageReference('/home/home.jsp'); // go to home page
return new PageReference('/' + o.AccountId); // or to the related Account's page
}
}
<apex:page standardController="Opportunity" extensions="redirectTestCtrl">
<apex:outputField value="{!o.AccountId}" />
<apex:form>
<apex:inputField value="{!o.Name}" />
<apex:commandButton value="Save" action="{!save}" />
</apex:form>
<span style="visibility:hidden">{!Opportunity.Name} {!Opportunity.AccountId}</span>
</apex:page>
The standard save() method may be called from an extension using ApexPages.StandardController. Here's a simple example of how it could be achieved:
Apex Page:
<apex:page standardController="Account" extensions="AccountExtension">
<apex:form >
<apex:pageMessages />
<apex:pageBlock title="Account">
<apex:pageBlockSection title="Account Details">
<apex:inputField value="{!account.Name}" />
</apex:pageBlockSection>
<apex:pageBlockButtons >
<apex:commandButton action="{!Save}" value="save" />
<apex:commandButton action="{!Cancel}" value="cancel" />
</apex:pageBlockButtons>
</apex:pageBlock>
</apex:form>
</apex:page>
Extension Class:
public class AccountExtension {
ApexPages.StandardController stdController;
public AccountExtension(ApexPages.StandardController controller) {
stdController = controller;
}
public PageReference save() {
stdController.save(); // calling standard save() method
return null; // return 'null' to stay on same page
}
}