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

Passing a string into an Order By Soql query
Hello,
I am trying to pass in an order by parameter into my soql query with example below. I want to be able to order based on the field name that i pass into the parameter. This is not working though. Any help would be great. Thanks
@AuraEnabled
public static List<Account> getAccounts(string orderby, Integer limits, Integer offsets) {
Integer intlimits = integer.valueOf(limits);
Integer intoffsets = integer.valueOf(offsets);
List<Account> accounts =
[SELECT Id, Name, Description, CARES_ActiveText__c FROM Account WHERE Type = 'Agency' Order By :orderby LIMIT :intlimits OFFSET :intoffsets];
//Add isAccessible() check
return accounts;
}
I am trying to pass in an order by parameter into my soql query with example below. I want to be able to order based on the field name that i pass into the parameter. This is not working though. Any help would be great. Thanks
@AuraEnabled
public static List<Account> getAccounts(string orderby, Integer limits, Integer offsets) {
Integer intlimits = integer.valueOf(limits);
Integer intoffsets = integer.valueOf(offsets);
List<Account> accounts =
[SELECT Id, Name, Description, CARES_ActiveText__c FROM Account WHERE Type = 'Agency' Order By :orderby LIMIT :intlimits OFFSET :intoffsets];
//Add isAccessible() check
return accounts;
}
I don't think the dynamic variables may bind on the below version.
List<Account> accounts =
[SELECT Id, Name, Description, CARES_ActiveText__c FROM Account WHERE Type = 'Agency' Order By :orderby LIMIT :intlimits OFFSET :intoffsets];
All Answers
String accountQuery = 'SELECT Id, Name, Description, CARES_ActiveText__c FROM Account WHERE Type = \''+'Agency'+'\' Order By :orderby LIMIT :intlimits OFFSET :intoffsets';
Database.query(accountQuery);
Thanks Karthik. I need a list of accounts though. Any way to accompish this using a list?
I don't think the dynamic variables may bind on the below version.
List<Account> accounts =
[SELECT Id, Name, Description, CARES_ActiveText__c FROM Account WHERE Type = 'Agency' Order By :orderby LIMIT :intlimits OFFSET :intoffsets];
http://sfdcmonkey.com/2017/01/26/display-record-with-pager-buttons-lightning-component/
Hope it will helps you, Kindly let us know if it helps you
Thanks