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
foodrunnerfoodrunner 

Custom Controller Error:

I am working on a visualforce page customizing the quote page layout with the quote line items. I am adapting the script from the Creating Compount Views turtorial on the wiki.

 

I am recieving the following error message:

Error: Compile Error: Return value must be of type: LIST<Quote> at line 9 column 9  

 

Below is my controller code:

 

public class MyConsoleController {
    public MyConsoleController() {

   }
 
    public Quote selectedQuote { get; set; }  
     
    public Quote[] getQuote() {
        return [SELECT id, Name, QuoteNumber, Created_Date__c, quote.Opportunity.AccountId, Quote_Line_Item__c,
                    Grand_Total__c,BillingAddress__c, BillingAddress2__c FROM Quote where id = :ApexPages.currentPage().getParameters().get('id')];
    
    }


    public QuoteLineItem[] getQuoteLineItems() {
        return [SELECT Id, PriceBookEntry.name, Quote__r.Grand_Total__c, QuoteID, Quantity, Quote_Item_Number__c, TotalPrice, ListPrice FROM QuoteLineItem
        WHERE QuoteId = :ApexPages.currentPage().getParameters().get('Id') order by Quote_Item_Number__c Asc];}

}

My questions:

 

1. What am I doing wrong in this controller?

2. What needs to be changed?

 

Thank you

Best Answer chosen by Admin (Salesforce Developers) 
ShwetaSShwetaS

Hi,

 

Replace your getQuote() function with the following:


public Quote getQuote()
{
        return [SELECT id, Name, QuoteNumber, Created_Date__c, quote.Opportunity.AccountId, Quote_Line_Item__c,
                    Grand_Total__c,BillingAddress__c, BillingAddress2__c FROM Quote where id = :ApexPages.currentPage().getParameters().get('id')];
   
    }


The Query which you are using will return only one record, so you don't need to use return type as an array(Quote[]).


Shweta
Salesforce Developer Support

If my answer solved your question, please mark it solved so I can help as many community members as possible!

All Answers

ShwetaSShwetaS

Hi,

 

Replace your getQuote() function with the following:


public Quote getQuote()
{
        return [SELECT id, Name, QuoteNumber, Created_Date__c, quote.Opportunity.AccountId, Quote_Line_Item__c,
                    Grand_Total__c,BillingAddress__c, BillingAddress2__c FROM Quote where id = :ApexPages.currentPage().getParameters().get('id')];
   
    }


The Query which you are using will return only one record, so you don't need to use return type as an array(Quote[]).


Shweta
Salesforce Developer Support

If my answer solved your question, please mark it solved so I can help as many community members as possible!

This was selected as the best answer
foodrunnerfoodrunner

Thank you for the reply. Unfortunately, I enter the new code to submit the following completed code

public class MyConsoleController {
    public MyConsoleController(ApexPages.StandardController controller) {

    }

   
public Quote getQuote() 
{
        return [SELECT id, Name, QuoteNumber, Created_Date__c, quote.Opportunity.AccountId, Quote_Line_Item__c, Grand_Total__c,BillingAddress__c, BillingAddress2__c FROM Quote where id = :ApexPages.currentPage().getParameters().get('id')];
    
    }
    public Quote selectedQuote { get; set; }

    public QuoteLineItem[] getQuoteLineItems() {
        return [SELECT Id, PriceBookEntry.name, Quote__r.Grand_Total__c, QuoteID, Quantity, Quote_Item_Number__c, TotalPrice, ListPrice FROM QuoteLineItem
        WHERE QuoteId = :ApexPages.currentPage().getParameters().get('Id') order by Quote_Item_Number__c Asc];}

}

 

I recieve the following error:

Error: Compile Error: Return value must be of type: Quote at line 10 column 9

Similar, but different.

foodrunnerfoodrunner

Thank you for the solution. I found that I had downloaded a class named Quote from one of the tutorials, which was causing the problem.