function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
SFDC n12SFDC n12 

Apex code help needed

Hi,

I am having a followng apex code which is reutrning the following error

"List has more than 1 rows assignment to S object"


VF PAGE :

<apex:page standardController="AccountExceptions__c" extensions="AF_ExecutiveReportController">
    <apex:form >
     <style>
        .headerRow .TableTitle {
            color: #CC0000 !important; 
        }
    </style>
        
        <apex:pageBlock title="Executive Committee Report" >
            <b>  <apex:outputText value="1.Total Exceptions ($50,000 threshold per Region):" style="Color:purple" /></b>
            <apex:pageBlockTable value="{!accexp}" var="item" rendered="{!accexp.Type__c=='Exception Adjustment' || accexp.Type__c=='Business Relationship Adjustment'}">
               <b> <apex:column headerValue="Region" headerClass="TableTitle"/> </b>
               <b> <apex:column  headerValue="TotalExceptions" Value="{!accexp.Total_Amount_of_Current_Exception__c }" headerClass="TableTitle"/> </b>
            </apex:pageBlockTable> 
        </apex:pageBlock>
    </apex:form>
</apex:page>


MY CONTROLLER :


public class AF_ExecutiveReportController {
public AccountExceptions__c accexp{get; set; }



  /**
    ** Constructor
    **/
   public AF_ExecutiveReportController (ApexPages.StandardController controller) {
   
   accexp= [Select Id,Account__c,ADR_Month__c,DOSUser__c,Total_Amount_of_Current_Exception__c FROM AccountExceptions__c WHERE ADR_Month__c!=null  ];
   
   }


}

i want to display alll the values for the field i called in my vf page


Help me what do i need to change in my code

Thanks in Advance
Best Answer chosen by SFDC n12
Ravi NarayananRavi Narayanan
public class AF_ExecutiveReportController {
public List<AccountExceptions__c> accexp{get; set; }



  /**
    ** Constructor
    **/
   public AF_ExecutiveReportController (ApexPages.StandardController controller) {
   accexp=new list<AccountExceptions__c>();
   accexp= [Select Id,Account__c,ADR_Month__c,DOSUser__c,Total_Amount_of_Current_Exception__c FROM AccountExceptions__c WHERE ADR_Month__c!=null  ];
   
   }


}

Mark as best answer if it solves your problem :) 

All Answers

RamuRamu (Salesforce Developers) 
As the query returns more than 1 record, you would assign the results to a list variable rather than a single sobject hence the issue. The below post outlines a similar issue

http://salesforce.stackexchange.com/questions/37157/error-on-a-different-test-class-list-has-more-than-1-row-for-assignment-to-sobj
SFDC n12SFDC n12
so should i use a list like below 

List<AccountExceptions__c>accexp= [Select Id,Account__c,ADR_Month__c,DOSUser__c,Total_Amount_of_Current_Exception__c FROM AccountExceptions__c WHERE ADR_Month__c!=null  ];


and in my vf use


           <b> <apex:column  headerValue="TotalExceptions" Value="{!accexp.Total_Amount_of_Current_Exception__c }" headerClass="TableTitle"/> </b>

let me know if its right ?

Thanks
Ravi NarayananRavi Narayanan
public class AF_ExecutiveReportController {
public List<AccountExceptions__c> accexp{get; set; }



  /**
    ** Constructor
    **/
   public AF_ExecutiveReportController (ApexPages.StandardController controller) {
   accexp=new list<AccountExceptions__c>();
   accexp= [Select Id,Account__c,ADR_Month__c,DOSUser__c,Total_Amount_of_Current_Exception__c FROM AccountExceptions__c WHERE ADR_Month__c!=null  ];
   
   }


}

Mark as best answer if it solves your problem :) 
This was selected as the best answer