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
HTANIRSHTANIRS 

custom controller record id is displaying Error

Hi Friends,

I have created a custom controller and a vf page and when I run the vf page I am getting List has no Rows error.

Kindly needed your help to resolve this issue.

Below is my class and VF code.
 
Apex Class:

public class quoteController {

    private final SBQQ__Quote__c quotePDF;
    private final SBQQ__Quote__c quoteOpp;
    private final SBQQ__Quote__c quoteProd;

    public quoteController() {
        // Query for QuoteLineItem
        quotePDF = [SELECT Id, SBQQ__Account__r.Name, SBQQ__BillingCity__c, SBQQ__BillingName__c, SBQQ__ShippingCity__c, SBQQ__ShippingName__c, 
                           (Select Id, SBQQ__ProductName__c, SBQQ__Quantity__c, SBQQ__Description__c, SBQQ__ListPrice__c, SBQQ__NetTotal__c from SBQQ__LineItems__r) 
                      FROM SBQQ__Quote__c
                      WHERE Id = :ApexPages.currentPage().getParameters().get('id')];
    
        // Query for Quote Opportunity
        quoteOpp = [SELECT Id, SBQQ__Opportunity2__r.Vehicle_Make__c, SBQQ__Opportunity2__r.Rego_Fleet_Number__c, SBQQ__Opportunity2__r.Vin_Number__c, SBQQ__Opportunity2__r.Odometer__c, 
                           SBQQ__Opportunity2__r.Vehicle_Model__c
                      FROM SBQQ__Quote__c
                      WHERE Id = :ApexPages.currentPage().getParameters().get('id')];
                      
        // Query for Quote Product
        quoteProd = [SELECT Id, (Select Id, SBQQ__Product__r.Refrigeration_Gas__c
                               from SBQQ__LineItems__r)
                       FROM SBQQ__Quote__c
                       WHERE Id = :ApexPages.currentPage().getParameters().get('id')];    

    }

    public SBQQ__Quote__c getquotePDF(){
        return quotePDF; 
    }
    
    public SBQQ__Quote__c getquoteOpp(){
        return quoteOpp;
    }
    
    public SBQQ__Quote__c getquoteProd(){
        return quoteProd;
    }
}
 
VF Page:

<apex:page controller="quoteController" tabStyle="SBQQ__Quote__c" showHeader="false" sidebar="false" standardStylesheets="false" applyBodyTag="false" applyHtmlTag="false">
    <html>               
        <body> 
        <apex:pageBlock >
            <apex:pageBlockTable columns="5" border="1" cellspacing="0" cellPadding="5" width="95%" value="{!quotePDF}" var="myOrder">                    
                <apex:column value="{!myOrder.SBQQ__Account__r.Name}" />        
                <apex:column value="{!myOrder.SBQQ__BillingCity__c}" />        
                <apex:column value="{!myOrder.SBQQ__BillingName__c}" />
                <apex:column headerValue="QTY">
                    <apex:outputText value=" " />
                </apex:column>
                <apex:column value="{!myOrder.SBQQ__ShippingCity__c}" />        
            </apex:pageBlockTable>
        </apex:pageBlock> <p class="onepointfive"/>
        
        <apex:pageBlock >
            <apex:pageBlockTable columns="5" border="1" cellspacing="0" cellPadding="5" width="95%" value="{!quoteOpp}" var="quoteOpp">                    
                <apex:column value="{!quoteOpp.SBQQ__Opportunity2__r.Vehicle_Make__c}" />        
                <apex:column value="{!quoteOpp.SBQQ__Opportunity2__r.Rego_Fleet_Number__c }" />        
                <apex:column value="{!quoteOpp.SBQQ__Opportunity2__r.Vin_Number__c }" />
                <apex:column headerValue="QTY">
                    <apex:outputText value="{!quoteOpp.SBQQ__Opportunity2__r.Odometer__c}" />
                </apex:column>
                <apex:column value="{!quoteOpp.SBQQ__Opportunity2__r.Vehicle_Model__c}" />
            </apex:pageBlockTable>
        </apex:pageBlock> <p class="onepointfive"/>
        
        <apex:pageBlock >
            <apex:pageBlockTable columns="5" border="1" cellspacing="0" cellPadding="5" width="100%" value="{!quotePDF.SBQQ__LineItems__r}" var="OrderItems" >
                <apex:column headerValue="Product Name">
                    <apex:outputField value="{!OrderItems.SBQQ__ProductName__c}"/>
                </apex:column>
                <apex:column headerValue="PartNumber">
                    <apex:outputField value="{!OrderItems.SBQQ__Quantity__c}"/>
                </apex:column>
                <apex:column headerValue="Item Type">
                    <apex:outputField value="{!OrderItems.SBQQ__Description__c}"/>
                </apex:column>
                <apex:column headerValue="Option Type">
                    <apex:outputText value="{!OrderItems.SBQQ__ListPrice__c}"/>
                </apex:column>
                <apex:column headerValue="Value">
                    <apex:outputField value="{!OrderItems.SBQQ__NetTotal__c}"/>
                </apex:column>                                                                              
            </apex:pageBlockTable>
        </apex:pageBlock> <p class="onepointfive"/>
        
        <apex:pageBlock >
            <apex:pageBlockTable columns="5" border="1" cellspacing="0" cellPadding="5" width="100%" value="{!quoteProd.SBQQ__LineItems__r}" var="prod" >
                <apex:column headerValue="Refrigeration Gas">
                    <apex:outputField value="{!prod.SBQQ__Product__r.Refrigeration_Gas__c}"/>
                </apex:column>
                                -->                                            
            </apex:pageBlockTable>
        </apex:pageBlock> <p class="onepointfive"/>
           
        </body>
    </html>    
</apex:page>

Thanks in Advance.
Best Answer chosen by HTANIRS
Avishek Nanda 14Avishek Nanda 14
Hi HTANIRS,

You can have these in Constructer. 
 
public class quoteController {
    
    private final SBQQ__Quote__c quotePDF;
    private final SBQQ__Quote__c quoteOpp;
    private final SBQQ__Quote__c quoteProd;
    
    public quoteController() {
        // Query for QuoteLineItem
        List<SBQQ__Quote__c> sbqLst new List<SBQQ__Quote__c> = [SELECT Id, SBQQ__Account__r.Name, SBQQ__BillingCity__c, SBQQ__BillingName__c, SBQQ__ShippingCity__c, SBQQ__ShippingName__c, 
                                                                (Select Id, SBQQ__ProductName__c, SBQQ__Quantity__c, SBQQ__Description__c, SBQQ__ListPrice__c, SBQQ__NetTotal__c from SBQQ__LineItems__r) 
                                                                FROM SBQQ__Quote__c
                                                                WHERE Id = :ApexPages.currentPage().getParameters().get('id')];
        if(sbqLst.size()>0) {
            quotePDF.add(sbqLst);
        }
        
        // Query for Quote Opportunity
        List<SBQQ__Quote__c> sbqLst2 new List<SBQQ__Quote__c> = [SELECT Id, SBQQ__Opportunity2__r.Vehicle_Make__c, SBQQ__Opportunity2__r.Rego_Fleet_Number__c, SBQQ__Opportunity2__r.Vin_Number__c, SBQQ__Opportunity2__r.Odometer__c, 
                                                                 SBQQ__Opportunity2__r.Vehicle_Model__c
                                                                 FROM SBQQ__Quote__c
                                                                 WHERE Id = :ApexPages.currentPage().getParameters().get('id')];
        if(sbqLst2.size()>0) {
            quoteOpp.add(sbqLst);
        }
        
        
        // Query for Quote Product
        List<SBQQ__Quote__c> sbqLst3 new List<SBQQ__Quote__c> = [SELECT Id, (Select Id, SBQQ__Product__r.Refrigeration_Gas__c
                                                                             from SBQQ__LineItems__r)
                                                                 FROM SBQQ__Quote__c
                                                                 WHERE Id = :ApexPages.currentPage().getParameters().get('id')];
        if(sbqLst2.size()>0) {
            quoteProd.add(sbqLst);
        }
        
    }
    
    public SBQQ__Quote__c getquotePDF(){
        return quotePDF; 
    }
    
    public SBQQ__Quote__c getquoteOpp(){
        return quoteOpp;
    }
    
    public SBQQ__Quote__c getquoteProd(){
        return quoteProd;
    }
}

 

All Answers

Avishek Nanda 14Avishek Nanda 14
Hi HTANIRS,

One of above query is not returning any number of records. The error "List has no rows  occurs when query doesn't return any rows.
 
While a SELECT normally returns an array/list, these statements are using the shorthand syntax that assumes only one row is returned.
What’s not obvious is that it also assumes that exactly one row is returned!

You could do something like this below.
 
List<SBQQ__Quote__c> sbqqList = [SELECT Id, SBQQ__Account__r.Name, SBQQ__BillingCity__c, SBQQ__BillingName__c, SBQQ__ShippingCity__c, SBQQ__ShippingName__c, 
                           (Select Id, SBQQ__ProductName__c, SBQQ__Quantity__c, SBQQ__Description__c, SBQQ__ListPrice__c, SBQQ__NetTotal__c from SBQQ__LineItems__r) 
                      FROM SBQQ__Quote__c
                      WHERE Id = :ApexPages.currentPage().getParameters().get('id')];

If(sbqqList.size() > 0) {
    quotePDF.add(sbqqList);
}

Same goes for others as well. And then Return the list on Page. 

Mark this as your best answer to help others if this solves your problem. 

Regards,
Avishek 
HTANIRSHTANIRS
Hi Avishek,

Thanks for your reply. May I know where should I implement this change. In Constructor or PageReference.

Thanks
Avishek Nanda 14Avishek Nanda 14
Hi HTANIRS,

You can have these in Constructer. 
 
public class quoteController {
    
    private final SBQQ__Quote__c quotePDF;
    private final SBQQ__Quote__c quoteOpp;
    private final SBQQ__Quote__c quoteProd;
    
    public quoteController() {
        // Query for QuoteLineItem
        List<SBQQ__Quote__c> sbqLst new List<SBQQ__Quote__c> = [SELECT Id, SBQQ__Account__r.Name, SBQQ__BillingCity__c, SBQQ__BillingName__c, SBQQ__ShippingCity__c, SBQQ__ShippingName__c, 
                                                                (Select Id, SBQQ__ProductName__c, SBQQ__Quantity__c, SBQQ__Description__c, SBQQ__ListPrice__c, SBQQ__NetTotal__c from SBQQ__LineItems__r) 
                                                                FROM SBQQ__Quote__c
                                                                WHERE Id = :ApexPages.currentPage().getParameters().get('id')];
        if(sbqLst.size()>0) {
            quotePDF.add(sbqLst);
        }
        
        // Query for Quote Opportunity
        List<SBQQ__Quote__c> sbqLst2 new List<SBQQ__Quote__c> = [SELECT Id, SBQQ__Opportunity2__r.Vehicle_Make__c, SBQQ__Opportunity2__r.Rego_Fleet_Number__c, SBQQ__Opportunity2__r.Vin_Number__c, SBQQ__Opportunity2__r.Odometer__c, 
                                                                 SBQQ__Opportunity2__r.Vehicle_Model__c
                                                                 FROM SBQQ__Quote__c
                                                                 WHERE Id = :ApexPages.currentPage().getParameters().get('id')];
        if(sbqLst2.size()>0) {
            quoteOpp.add(sbqLst);
        }
        
        
        // Query for Quote Product
        List<SBQQ__Quote__c> sbqLst3 new List<SBQQ__Quote__c> = [SELECT Id, (Select Id, SBQQ__Product__r.Refrigeration_Gas__c
                                                                             from SBQQ__LineItems__r)
                                                                 FROM SBQQ__Quote__c
                                                                 WHERE Id = :ApexPages.currentPage().getParameters().get('id')];
        if(sbqLst2.size()>0) {
            quoteProd.add(sbqLst);
        }
        
    }
    
    public SBQQ__Quote__c getquotePDF(){
        return quotePDF; 
    }
    
    public SBQQ__Quote__c getquoteOpp(){
        return quoteOpp;
    }
    
    public SBQQ__Quote__c getquoteProd(){
        return quoteProd;
    }
}

 
This was selected as the best answer