You need to sign in to do that
Don't have an account?
Problem in insertion
Hello..
I'm trying to insert an entry in a custom object..
Code in apex is :
<apex:page controller="ProgramController">
<apex:form >
<apex:pageBlock title="Program Section">
<apex:pageBlockButtons >
<apex:commandButton value="Save" action="{!save}" />
</apex:pageBlockButtons>
</apex:pageBlock>
</apex:form>
</apex:page>
Controller -- ProgramController
public with sharing class ProgramController
{
public void save()
{
try
{
Program__c tempProgram = new Program__c(Payment__c= false,
ParentProgram__c='testProg');
insert tempProgram ;
}
catch(System.Exception e)
{
ApexPages.addMessages(e);
//throw e;
// return null;
}
}
}
It's working fine for me .. now im trying to add some other controls like selectlist etc and tryin to format page accordingly.
The new apex page is like
Apex:
<!-- <apex:page controller="ProgramController">
<apex:page standardcontroller="Program__c" extensions="ProgramController">
-->
<apex:page controller="ProgramController">
<h2>Program</h2>
<apex:form >
<apex:pageBlock title="Program Section">
<apex:pageBlockButtons >
<apex:commandButton value="Save" action="{!save}" />
<apex:commandButton value="Save & New" action="{!save}" />
<apex:commandButton value="Close" rerender="out" status="status" />
</apex:pageBlockButtons>
<apex:pageBlockSection title="My Content Section" columns="2">
<apex:pageBlockSectionItem >
<apex:outputLabel >
<h1>Title:</h1>
</apex:outputLabel>
<apex:inputtext id="ProgramName" />
</apex:pageBlockSectionItem>
<apex:pageBlockSectionItem >
<apex:outputLabel >
<h1>Program Type:</h1>
</apex:outputLabel>
<apex:selectList value="{!types}" size="1" id="ProgType">
<apex:selectOptions value="{!type}" />
</apex:selectList>
</apex:pageBlockSectionItem>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
and Controller is
ProgramController:
public with sharing class ProgramController
{
Public Program__c auto{get; set;}
String[] types= new String[]{};
/*
public ProgramController() {
}
public ProgramController(ApexPages.StandardController controller)
{
}
public PageReference ProgramController()
{
return null;
}*/
public List<SelectOption> getType()
{
List<SelectOption> options = new List<SelectOption>();
options.add(new SelectOption('0.','Payment Program'));
options.add(new SelectOption('1','Non-Payment Program'));
return options;
}
public String[] getTypes()
{
return types;
}
public void setTypes(String[] types)
{
this.types= types;
}
public void save()
{
try
{
Program__c tempProgram = new Program__c(Payment__c= false,
ParentProgram__c='testProg');
insert tempProgram ;
}
catch(System.Exception e)
{
ApexPages.addMessages(e);
//throw e;
// return null;
}
}
}
Now in this case, it's not allowing me to insert .. and i jus found that is because of the populating SelectLists and due to <apex:pageBlockSectionItem > tag in page ... if i exclude these two things .. all insertions are working fine. I don't have any idea where i'm going wrong..
Any kind of help will b appreciated..
Thnx!!
I ve resolved this problem after spending my hours on it..
all i changed is Strings Array in String and it's working ..
:smileyhappy:
All Answers
You might want to swap the statements on gettype & gettypes.
<apex:selectList value="{!types}" size="1" id="ProgType">
<apex:selectOptions value="{!type}" />
replaced as
<apex:selectList value="{!type}" size="1" id="ProgType">
<apex:selectOptions value="{!types}" />
Usually,we use a valid column name on selectlist value something like
<apex:selectList value="{!Program__c.Type__c}" size="1" id="ProgType">
I ve resolved this problem after spending my hours on it..
all i changed is Strings Array in String and it's working ..
:smileyhappy:
Glad that it worked.
Did my earlier post helpful to you? Could as well post the line that you changed.
Thank you ...
but yea i didn't swap between lines ..
Thanks anyways
cheers;
Aish.!!