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

Lightning error : Return type is a wrapper class
Hi,
I am having an apex controller with the following method whose return type is again a different class. Below is my code:
@AuraEnabled
public static AccountPagerWrapper getData (Decimal pageNumber ,Integer recordToDisply)
{
Integer pageSize = recordToDisply;
Integer offset = ((Integer)pageNumber - 1) * pageSize;
String queryCount = 'SELECT count() FROM Account';
String finalQuery = 'dynamic query';
List<Account> returnList = new List<Account>();
returnList = database.query(finalQuery);
AccountPagerWrapper obj = new AccountPagerWrapper();
obj.pageSize = pageSize;
obj.page = (Integer) pageNumber;
obj.total = database.countQuery(queryCount);
obj.accounts = returnList;
return obj;
}
public class AccountPagerWrapper {
@AuraEnabled public Integer pageSize {get;set;}
@AuraEnabled public Integer page {get;set;}
@AuraEnabled public Integer total {get;set;}
@AuraEnabled public List<Account> accounts {get;set;}
}
Can anyone tell how to assign the dynamic query results in accounts property of the AccountPagerWrapper. Line is marked with bold.
I am simply assigning the dynamic query results in the property but it is throwing an error while binding it with the table.
Thnx,
Vai
I am having an apex controller with the following method whose return type is again a different class. Below is my code:
@AuraEnabled
public static AccountPagerWrapper getData (Decimal pageNumber ,Integer recordToDisply)
{
Integer pageSize = recordToDisply;
Integer offset = ((Integer)pageNumber - 1) * pageSize;
String queryCount = 'SELECT count() FROM Account';
String finalQuery = 'dynamic query';
List<Account> returnList = new List<Account>();
returnList = database.query(finalQuery);
AccountPagerWrapper obj = new AccountPagerWrapper();
obj.pageSize = pageSize;
obj.page = (Integer) pageNumber;
obj.total = database.countQuery(queryCount);
obj.accounts = returnList;
return obj;
}
public class AccountPagerWrapper {
@AuraEnabled public Integer pageSize {get;set;}
@AuraEnabled public Integer page {get;set;}
@AuraEnabled public Integer total {get;set;}
@AuraEnabled public List<Account> accounts {get;set;}
}
Can anyone tell how to assign the dynamic query results in accounts property of the AccountPagerWrapper. Line is marked with bold.
I am simply assigning the dynamic query results in the property but it is throwing an error while binding it with the table.
Thnx,
Vai
If you need to assign a dynamic query then you can assign the query in the string
for example-
Whatever you want to query assign them into string format then concatenate it into final query string. The above example is for your understanding.
I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.
Thanks and Regards,
Ajay Dubedi
www.ajaydubedi.com