How to resolve this issue - system.queryexception: list has more than 1 row for assignment to sobject?

709    Asked by Aalapprabhakaran in Salesforce , Asked on Apr 28, 2023

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 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, Merchant_Category_Code__c FROM Merchant_Profile__c WHERE Profile_Account_Name__c = '001O000000bQFnyIAG']; } }
Answered by David Piper
 To resolve this issue - system.queryexception: list has more than 1 row for assignment to sobject -
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 mp { get; set; }

Your Answer

Interviews

Parent Categories