You need to sign in to do that
Don't have an account?

I am facing error on apex class "List has more than 1 row for assignment to SObject"
Hi All,
I am facing errror when execute this class through vf page and also it is showing one record instead of more record .
it is show error "List has more than 1 row for assignment to SObject
Error is in expression '{!getData}' in component <apex:commandButton> in page cpqvf: Class.ProductEntry.getData: line 13, column 1
An unexpected error has occurred. Your development organization has been notified.
"
Please help .
public class ProductEntry{
public List<sObjectWrapper> wrappers{get;set;}
Public string selectedname{get;set;}
public List<PricebookEntry> PriceEntry{get;set;}
public ProductEntry()
{
PriceEntry=new List<PricebookEntry>();
}
public void getData()
{
List<sObjectWrapper> wrapper=new List<sObjectWrapper>();
product2 productList=[select id,name,Units_of_Measure__c from product2 where Bundle_Type__c=:selectedname];
PriceBook2 pricebook=[select id from pricebook2 where name In('BlackBeltHelp V2')];
PriceEntry=[SELECT id,Name,Pricebook2Id,Product2Id,ProductCode,UnitPrice,UseStandardPrice FROM PricebookEntry WHERE Pricebook2Id=:pricebook.id and product2Id=:productList.id];
}
Public List<string> optionList=new List<String>{'Basic','Advance','Primium'};
Public List<Selectoption> getselectedaccnamefields(){
List<Selectoption> lstnamesel = new List<selectoption>();
lstnamesel.add(new selectOption('', '- None -'));
for(String s :optionList){
lstnamesel.add(new selectoption(s,s));
}
return lstnamesel;
}
}
and my viasulforce page is
<apex:page controller="ProductEntry">
<apex:form >
<apex:pageBlock title="Select Product List">
<apex:pageBlockSection columns="1">
<apex:pageBlockSectionItem >
<apex:outputLabel value="Bundle Type"/>
<apex:selectList size="1" value="{!selectedname}">
<apex:selectOptions value="{!selectedaccnamefields}"/>
</apex:selectList>
</apex:pageBlockSectionItem>
</apex:pageBlockSection>
<apex:pageBlockTable value="{!PriceEntry}" var="a">
<apex:column value="{!a.id}"/>
<apex:column value="{!a.name}"/>
<apex:column value="{!a.Pricebook2Id}"/>
<apex:column value="{!a.UnitPrice}"/>
<apex:column value="{!a.ProductCode}"/>
<apex:column value="{!a.UseStandardPrice}"/>
</apex:pageBlockTable>
<apex:pageBlockButtons >
<apex:commandButton value="GetData" action="{!getData}"/>
</apex:pageBlockButtons>
</apex:pageBlock>
</apex:form>
</apex:page>
I am facing errror when execute this class through vf page and also it is showing one record instead of more record .
it is show error "List has more than 1 row for assignment to SObject
Error is in expression '{!getData}' in component <apex:commandButton> in page cpqvf: Class.ProductEntry.getData: line 13, column 1
An unexpected error has occurred. Your development organization has been notified.
"
Please help .
public class ProductEntry{
public List<sObjectWrapper> wrappers{get;set;}
Public string selectedname{get;set;}
public List<PricebookEntry> PriceEntry{get;set;}
public ProductEntry()
{
PriceEntry=new List<PricebookEntry>();
}
public void getData()
{
List<sObjectWrapper> wrapper=new List<sObjectWrapper>();
product2 productList=[select id,name,Units_of_Measure__c from product2 where Bundle_Type__c=:selectedname];
PriceBook2 pricebook=[select id from pricebook2 where name In('BlackBeltHelp V2')];
PriceEntry=[SELECT id,Name,Pricebook2Id,Product2Id,ProductCode,UnitPrice,UseStandardPrice FROM PricebookEntry WHERE Pricebook2Id=:pricebook.id and product2Id=:productList.id];
}
Public List<string> optionList=new List<String>{'Basic','Advance','Primium'};
Public List<Selectoption> getselectedaccnamefields(){
List<Selectoption> lstnamesel = new List<selectoption>();
lstnamesel.add(new selectOption('', '- None -'));
for(String s :optionList){
lstnamesel.add(new selectoption(s,s));
}
return lstnamesel;
}
}
and my viasulforce page is
<apex:page controller="ProductEntry">
<apex:form >
<apex:pageBlock title="Select Product List">
<apex:pageBlockSection columns="1">
<apex:pageBlockSectionItem >
<apex:outputLabel value="Bundle Type"/>
<apex:selectList size="1" value="{!selectedname}">
<apex:selectOptions value="{!selectedaccnamefields}"/>
</apex:selectList>
</apex:pageBlockSectionItem>
</apex:pageBlockSection>
<apex:pageBlockTable value="{!PriceEntry}" var="a">
<apex:column value="{!a.id}"/>
<apex:column value="{!a.name}"/>
<apex:column value="{!a.Pricebook2Id}"/>
<apex:column value="{!a.UnitPrice}"/>
<apex:column value="{!a.ProductCode}"/>
<apex:column value="{!a.UseStandardPrice}"/>
</apex:pageBlockTable>
<apex:pageBlockButtons >
<apex:commandButton value="GetData" action="{!getData}"/>
</apex:pageBlockButtons>
</apex:pageBlock>
</apex:form>
</apex:page>
Please try below code..
Please let me know if this help!
Thanks
Shivdeep
All Answers
But i need to disply more than one record
Please try below code..
Please let me know if this help!
Thanks
Shivdeep
Try this: Let me know if it helps.
Thanks!