I'm building a simple Lightning Component that pulls in a set amount of accounts and displays them. However, I keep getting a Limit expression must be of type Integer
error message. I've hard-coded a number and set a variable to use in the SOQL with neither giving this error but for some reason the value being passed in is the only way that gives this error.
Here is the various pieces of code:
Apex
public with sharing class TestAccountCtrl {
@AuraEnabled
public static List<Account> returnAccountsAsTest(Integer limitAmount) {
List<Account> accounts = [SELECT Id FROM Account LIMIT :limitAmount];
return accounts;
}
}
I've also done the following in the Apex controller and all work without issues:
List<Account> accounts = [SELECT Id FROM Account LIMIT 15];
Integer amount = 15;
List<Account> accounts = [SELECT Id FROM Account LIMIT :amount];
String query = 'SELECT Id FROM Account LIMIT ' + limitAmount;
List<Account> accounts = Database.query(query);
Below is the rest of the code.
Component
<aura:component implements="forceCommunity:availableForAllPageTypes" controller="TestAccountCtrl">
<aura:attribute name="limitAmount" type="Integer" default="5" />
<aura:handler name="init" value="{!this}" action="{!c.retrieveAccounts}" />
</aura:component>
Design
<design:component label="Knowledge Articles">
<design:attribute name="limitAmount" label="Limit Amount" default="5" />
</design:component>
Controller
({
"retrieveAccounts" : function(cmp) {
var action = cmp.get("c.returnAccountsAsTest");
action.setParams({ limitAmount : cmp.get("v.limitAmount") });
action.setCallback(this, function(response) {
// process state here
});
$A.enqueueAction(action);
}
})
Logging shows that limitAmount
is an Integer with a non null value (15 in my tests). I'm not sure why it thinks the value I'm passing into the Apex function is not an integer. Is there something I'm missing in all of this?
LIMIT
values. I thought you had to go the dynamic route.