You need to sign in to do that
Don't have an account?
Sowing more than one row in apex:pageBlock
My Custom Visualforce page.
<apex:page controller="UnapprovedList">
<apex:pageBlock title="Opportunities">
<apex:pageBlockTable value="{!Opportunity}" var="item">
<apex:column value="{!item.Name}"/>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:page>
My Controller
public class UnapprovedList{
private final Opportunity opportunity;
public UnapprovedList() {
opportunity = [SELECT Id, Name FROM Opportunity limit 1];
// the page displays error if i remove limit 1.
//System.QueryException: List has more than 1 row for assignment to SObject
}
public Opportunity getOpportunity () {
return opportunity;
}
}
where is the problem?? i want to show more than one row but when i return multiple row the error pops up..
Any help would be appricated.
Use below code, error will be resolved.
All Answers
Use below code, error will be resolved.
Hi,
if you want to access more than one row then you need to use List to get the results.
i.e if u need to get opportunity records then u need to create a variable of List<opportunity> not opportunity.
private final Opportunity opportunity;
replace it with
List<Opprtunity> opptyList;
public UnapprovedList() {
opptyList = [SELECT Id, Name FROM Opportunity]; // Now it will not give any error.
}
Please let me know if u have any problem on same and if this post helps u please throw KUDOS by click on star at left.