You need to sign in to do that
Don't have an account?
Binu 8
Dynamic Picklist not wrking
Hi ,
I have a visual force page which have a dynamic picklist.The select option data fetching from another object through custom controller.
When I am trying to save the visual force page seems this error "Error: Unknown property 'Auction__cStandardController.products'"
The code in visualforce:-
<apex:page standardController="Auction__c" extensions="cAuction" >
<apex:form >
<apex:pageBlock title="New Auction">
<apex:pageblockSection >
<apex:inputField value="{!auctionObj.Name}"/>
<apex:selectList size="1" title="Products">
<apex:selectOptions value="{!products}"></apex:selectOptions>
</apex:selectList>
</apex:pageblockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
The code in controller:-
public class cAuction {
public Auction__c auctionObj{get;set;}
public PageReference save(){
return null;
}
public cAuction(ApexPages.StandardController controller){
auctionObj = new Auction__c();
}
public List<selectOption> getproducts() {
List<selectOption> options = new List<selectOption>();
options.add(new selectOption('', '- None -'));
for (Procuct__c product : [SELECT Id, Name FROM Pocuct__c]) {
options.add(new selectOption(product.id, product.Name));
}
return options;
}
}
}
Let me know what will be the problem?
I have a visual force page which have a dynamic picklist.The select option data fetching from another object through custom controller.
When I am trying to save the visual force page seems this error "Error: Unknown property 'Auction__cStandardController.products'"
The code in visualforce:-
<apex:page standardController="Auction__c" extensions="cAuction" >
<apex:form >
<apex:pageBlock title="New Auction">
<apex:pageblockSection >
<apex:inputField value="{!auctionObj.Name}"/>
<apex:selectList size="1" title="Products">
<apex:selectOptions value="{!products}"></apex:selectOptions>
</apex:selectList>
</apex:pageblockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
The code in controller:-
public class cAuction {
public Auction__c auctionObj{get;set;}
public PageReference save(){
return null;
}
public cAuction(ApexPages.StandardController controller){
auctionObj = new Auction__c();
}
public List<selectOption> getproducts() {
List<selectOption> options = new List<selectOption>();
options.add(new selectOption('', '- None -'));
for (Procuct__c product : [SELECT Id, Name FROM Pocuct__c]) {
options.add(new selectOption(product.id, product.Name));
}
return options;
}
}
}
Let me know what will be the problem?
Your code is perfect just correct the below line in your code
either it is Procuct__c or Pocuct__c, use Correct API name.
If this solves your problem, kindly mark it as the best answer.
Thanks,
Vatsal
You have to call insert in save method function.
public PageReference save()
{
insert auctionObj;
return null;
}
Its working fine to me.Check it once again and Let me know..
Thank You
I rewrite the code.But the error is not fixed.I think this line is the problem for error,
<apex:selectOptions value="{!products}" ></apex:selectOptions>
The visual force page says "Error: Unknown property 'Auction__cStandardController.products'".Which means Not getting the products....Is this is the right way to fetching the value from controller. Because the in visual force we mentioned value="{!products}".But we have no variable such as products in controller.Only we have a getProducts() function.Also i am attaching the screenshot.please chek.
Apex code:-
public class cAuction {
public Auction__c auctionObj{get;set;}
public PageReference save(){
insert auctionObj;
return null;
}
public cAuction(ApexPages.StandardController controller){
auctionObj = new Auction__c();
}
public List<selectOption> getProducts() {
List<selectOption> options = new List<selectOption>();
options.add(new selectOption('', '- None -'));
for (Procuct__c product : [SELECT Id, Name FROM Procuct__c]) {
options.add(new selectOption(product.id, product.Name));
}
return options;
}
}
}
Now try this in your page..I tried this with my custom object..
Class:
public class cAuction {
public Housing_Resource__c auctionObj{get;set;}
public PageReference save(){
insert auctionObj;
return null;
}
public cAuction(ApexPages.StandardController controller){
auctionObj = new Housing_Resource__c();
}
public string strproduct{get;set;}
public List<selectOption> getproducts() {
List<selectOption> options = new List<selectOption>();
options.add(new selectOption('', '- None -'));
for (Opportunity product : [SELECT Id, Name FROM Opportunity]) {
options.add(new selectOption(product.id, product.Name));
}
return options;
}
}
Page:
<apex:page standardController="Housing_Resource__c" extensions="cAuction" >
<apex:form >
<apex:pageBlock title="New Auction">
<apex:pageblockSection >
<apex:inputField value="{!auctionObj.Name}"/>
<apex:selectList size="1" title="Products" value="{!strproduct}">
<apex:selectOptions value="{!products}"></apex:selectOptions>
</apex:selectList>
</apex:pageblockSection>
<apex:commandButton value="Save" action="{!save}"/>
</apex:pageBlock>
</apex:form>
</apex:page>
If this this solves your problem,Please let me know..
Thank You
So I changed the object name to Auction__c.That time the previous error is showing. I also changed the controller code which you wrote in this ticket.
Please Check API Names for fields and Objects which you have created in your org.Because otherwise its working fine to me..