You need to sign in to do that
Don't have an account?
sp13
query all account ordered by latest contact
I have a field TotalContacts__c which has the total numbers of contacts of each account. I need to query all contacts ordered by the total number of contacts [SELECT Name FROM Account ORDER BY TotalContacts__c DESC] but I also need to order them by which has the latest contact.
For example, if Account 1, Account 2 and Account 3 all has 5 TotalContacts__c, then I need them to be ordered by which one has the lastest related contact.
example:
Account Name TOtalContacts__c (last contact related to account is created on:
Account 1 5 08/20/2015
Account 3 5 08/18/2015
Account 2 5 07/30/2015
For example, if Account 1, Account 2 and Account 3 all has 5 TotalContacts__c, then I need them to be ordered by which one has the lastest related contact.
example:
Account Name TOtalContacts__c (last contact related to account is created on:
Account 1 5 08/20/2015
Account 3 5 08/18/2015
Account 2 5 07/30/2015
You could use a wrapper class with a custom sort method using the Comparable interface. Then, query your Accounts and child Contact records and feed them to the wrapper class.
Wrapper Class:
Query your accounts and custom sort:
Hope that helps,
Clint
Line 5 should be