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
lovetolearnlovetolearn 

Compile Error

Error: Compile Error: Return value must be of type: LIST<Account> at line 4 column 9 <-- this is the error i get when i try to run the following code:

 

public class MyController {
    public List<Account> getMyAccounts ()
    {
        return [select Id, Name, Accountnumber from Account
        Order by LastmodifiedDate DESC Limit 10];
    }
}

 

please let me know where i went wrong. Thank you.

Best Answer chosen by Admin (Salesforce Developers) 
aalbertaalbert

You aren't explicitly returning a List<>. Try this:

 

 

public class MyController {
    public List<Account> getMyAccounts ()
    {
        List<Account> temp= [select Id, Name, Accountnumber from Account Order by LastmodifiedDate DESC Limit 10];
        return temp; 
    }
}

 

 

All Answers

aalbertaalbert

You aren't explicitly returning a List<>. Try this:

 

 

public class MyController {
    public List<Account> getMyAccounts ()
    {
        List<Account> temp= [select Id, Name, Accountnumber from Account Order by LastmodifiedDate DESC Limit 10];
        return temp; 
    }
}

 

 

This was selected as the best answer
lovetolearnlovetolearn

 


aalbert wrote:

You aren't explicitly returning a List<>. Try this:

 

 

public class MyController {
    public List<Account> getMyAccounts ()
    {
        List<Account> temp= [select Id, Name, Accountnumber from Account Order by LastmodifiedDate DESC Limit 10];
        return temp; 
    }
}

 

 


 

i tried this code, but it's still giving me a compile error:

 

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

lovetolearnlovetolearn

I am following a VF tutorial for this. The first thing i did was create a VF page with the following code:

 

<apex:page controller="MyController">
    <apex:form>
        <apex:dataList value="{!myaccounts}" var="acct">
            <apex:outputText value="{!acct.name}"></apex:outputText>
        </apex:dataList>
    </apex:form>
</apex:page>

 

Then I had SF create a public sharing class called MyController for me and create apex method getmyaccounts. The next thing i did was click on the controller tab and enter the following code:

 

public with sharing class MyController {

 

    public List<Account> getMyAccounts () {

        return [select Id, Name, Accountnumber from Account ORDER BY

        LastModifiedDate DESC LIMIT 10];

    }

}

 

thats when i got the error.

Raumil SetalwadRaumil Setalwad

Hello friend,

You just need to modify the code as below

 

 

For VF page
<apex:page controller="MyController">
    <apex:form>
        <apex:dataList value="{!accounts}" var="acct">
            <apex:outputText value="{!acct.name}"></apex:outputText>
        </apex:dataList>
    </apex:form>
</apex:page>


For Controller

public class MyController{
   List<Accounts> accounts;

   public List<Accounts> getAccounts(){
    accounts = [select Name from Account Limit 10];
    return accounts
   }
}

 

 

Hope this helps

Regards

 

Raumil Setalwad

 

Bhawani SharmaBhawani Sharma

Nothing is wrong here . I tried the same code in my org and  I was able to compile it.

lovetolearnlovetolearn

 


Tech Force wrote:

Nothing is wrong here . I tried the same code in my org and  I was able to compile it.


which code did you try?

 

lovetolearnlovetolearn

 


Raumil Setalwad wrote:

Hello friend,

You just need to modify the code as below

 

 

For VF page
<apex:page controller="MyController">
    <apex:form>
        <apex:dataList value="{!accounts}" var="acct">
            <apex:outputText value="{!acct.name}"></apex:outputText>
        </apex:dataList>
    </apex:form>
</apex:page>


For Controller

public class MyController{
   List<Accounts> accounts;

   public List<Accounts> getAccounts(){
    accounts = [select Name from Account Limit 10];
    return accounts
   }
}

 

 

Hope this helps

Regards

 

Raumil Setalwad

 


 

sorry i clicked the accept as solution button by accident...

 

I tried this code and I am still getting the same error message.

Raumil SetalwadRaumil Setalwad

I am sorry its my mistake

 

 

if(account == null){
      account = [select Name from Account LimiT 10];
}

 Also check the following link for <apex:datalist> command

http://www.salesforce.com/us/developer/docs/pages/Content/pages_compref_dataList.htm

 

 

 

Hope this helps

Regards

Raumil Setalwad

jcaldjcald
I, too, am going through this tutorial. Why does saleforce use this tutortial when it does not work?

I am still trying to figure out what is above. Please give the Controller and VF page at its entire.

Thanks
geeta garggeeta garg
Hi  lovetolearn,

Just check your all apex classes, by mistake you created the class of Account. So firstly delete that class and then save your code.
I think that it will solve your problem.

Thanks,
Geeta