You need to sign in to do that
Don't have an account?
Rebecca Vanderslice
SOQL Order By with records owned by current user showing first but other records are still in the list
I want to show the results of a SOQL query to a user including those records that are not owned by the user. But with the current user owned records appearing first in the list. Then within the group of records owned by the current user, order by a value field.
Is there a creative way to put a temp column into the SOQL so that i can order by 1 or 2 first and then by value? Here's what we are doing currently but i want to try to eliminate have to create 2 queries.
Is there a creative way to put a temp column into the SOQL so that i can order by 1 or 2 first and then by value? Here's what we are doing currently but i want to try to eliminate have to create 2 queries.
private List<Site_Account__c> createSiteAccountsList() {
List<Site_Account__c> siteAccountsOwnedByLoggedInUser = [SELECT TotalValue__c, Owner.Name, OwnerId, Name, Contact_Id__r.Name, Contact_Id__c, AccountDID__c, Currency__c, AccountType__c FROM Site_Account__c WHERE Account_Id__c =: selectedAccountId AND OwnerId =: UserInfo.getUserId() ORDER BY TotalValue__c DESC LIMIT 1000]; List<Site_Account__c> siteAccountsNotOwnedByLoggedInUser = [SELECT TotalValue__c, Owner.Name, OwnerId, Name, Contact_Id__r.Name, Contact_Id__c, AccountDID__c, Currency__c, AccountType__c FROM Site_Account__c WHERE Account_Id__c =: selectedAccountId AND OwnerId !=: UserInfo.getUserId() ORDER BY OwnerId, TotalValue__c DESC LIMIT 1000];
List<Site_Account__c> siteAccounts = new List<Site_Account__c>(); siteAccounts.addAll(siteAccountsOwnedByLoggedInUser); siteAccounts.addAll(siteAccountsNotOwnedByLoggedInUser); return siteAccounts; }Any creative ideas are welcome!
All Answers
$User.Id = OwnerId