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

List has no rows for assignment to SObject error
I have a custom Object TimeRecords__c and I want to display the VF Page as a pdf in the object using a custom Button. I created a Visualforce page and a controller class for the Custom Button. On clicking the custom button I get the 'List has no rows to SObject error'.
My VF Page Code is as below:
Controller Class:
Could someone of you folks help me sort out this error. I have tried many solutions but they don't seem to work.
Thanks in Advance.
My VF Page Code is as below:
<apex:page standardController="TimeRecords__c" showHeader="false" renderas="pdf" extensions="TimeRecord"> <table border="0" cellspacing="0" cellpadding="0" width="100%" id="table1"> <tr> <td > <img src='{!URLFOR($Resource.VinasLogo)}' title="logo" /> </td> <td align="right"><font face="Arial" > <b>Invoice for {!con.Name}</b> </font><br/> </td> </tr> <hr/> </table> <table border="0" cellspacing="0" cellpadding="0" width="100%" id="table1"> <tr> <td><font face="Arial" > {!$Organization.Name}<br/> {!$Organization.Street}<br/> {!$Organization.PostalCode} {!$Organization.City}<br/> {!$Organization.Country}<br/> </font></td> <td width="60%"> </td> <!--<td ><font face="Arial">Invoice number: <apex:repeat value="{!Opportunity.Invoices__r}" var="line2"> {!line2.name}</apex:repeat></font><br/> <font face="Arial">Invoice Date: <apex:repeat value="{!Opportunity.Invoices__r}" var="line2"> {!line2.Invoice_Date__c} </apex:repeat></font></td>--> </tr> </table> <br/> <hr/> <p><b><font face="Arial" color="#000080">Address Information</font></b></p> <table border="0" width="100%" id="table2"> <tr> <td> <font face="Arial">Bill To:<br/> {!con.MailingStreet}<br/> {!con.MailingCity}{!con.MailingState}{!con.MailingPostalCode}<br/> </font> </td> <td width="50%"></td> </tr> </table> <br/> <hr/> <p> </p> <hr/> <p align="center"><font face="Arial"><i>Copyright {!$Organization.Name}.</i></font></p> </apex:page>
Controller Class:
global with sharing class TimeRecord { public Contact con{get;set;} public TimeRecords__c TR{get;set;} public TimeRecord(ApexPages.StandardController cntrl){ this.TR = (TimeRecords__c) cntrl.getRecord(); TR=[SELECT Billable__c, Activity__c, Client__c, Client_Name__c,Date_of_Work__c, Entry_Type__c, Exclude_From_Invoice__c, Fees_Time__c, Matter__c, Overtime__c, Private_Description__c, Rate__c FROM TimeRecords__c WHERE Name=: ApexPages.currentPage().getParameters().get('id') ]; con=[SELECT Id, Name, MailingStreet, MailingCity, MailingState, MailingPostalCode FROM Contact ]; } }
Could someone of you folks help me sort out this error. I have tried many solutions but they don't seem to work.
Thanks in Advance.
Here is the latest code.
This worked for me.
All Answers
You either have to change your attribute defined, or the SOQL query that populates it.
it could be either or
Apart from this I do not see any issues. And, I don't see the custom button your are talking about, in your VF page.
I get the error:
Error: Unknown property 'VisualforceArrayList.Name'
OR
updating to:
It gives the same error:'List has no rows to SObject error'
The VF page is supposed to take data from the TimeRecords__c Object and the related Contact object.
Controller Class: VF Page:
Here is the latest code.
This worked for me.
SObject row was retrieved via SOQL without querying the requested field: TimeRecords__c.Client__c
I have accidentally mentioned it as TimeRecord__c in my controller code.
Can you change that and try?
Run the VF page once again and check the log file.
Also, can you please share your controller code as it is, once again?
But no harm. Good Luck!