I am trying to write a VF page to list all the id and name columns from a custom object but found an error "List has more than 1 row" in the VF page. Can anyone tell me what have I done wrong?

VF Page:

<apex:page Controller="MP_controller" showHeader="false" sidebar="false">
     <apex:pageBlockTable value="{! mp}" var="item">
        <apex:column value="{! item.id}"/>
        <apex:column value="{! item.name}"/>


Apex controller

global with sharing class MP_controller {
    public Merchant_Profile__c mp{get;set;}
    public MP_controller(){
        mp = [SELECT 
                ID, name, Profile_account_name__c, Merchant_ID__c, Bank_Code__c, Country_Code__c,
                Currency_Code__c, Merchant_Level__c, Merchant_Type__c, MSO__c, Region__c,
                Retail_Products__c, Transaction_Mode__c, Created_Date__c, Date_Disabled__c, Date_Live__c,
              FROM Merchant_Profile__c
              WHERE Profile_Account_Name__c = '001O000000bQFnyIAG'];

Your query is returning more than one record, but the variable 'mp' is a single instance and not a List of Merchant_Profile__c. If you change the code as following, it will work.

public **List<Merchant_Profile__c>** mp{get;set;}
  • So can we take mp into an array while querying? – orangeguy May 19 '16 at 17:51
  • What exactly do you mean @Mr.Orange? mp is now a list and list is an array. – ajinkyah May 23 '16 at 9:49

The pageBlockTable's value attribute expected a collection of data:

value: The collection of data displayed in the page block table.

In your case this is a single object. You have to change it to the list for example:

public List<Merchant_Profile__c> mp { get; set; }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.