+ Start a Discussion

How do you Rank a record?

Hi there,


I there, I would like to rank an account based on the Total Revenue. But not quite sure how to implement this. Has anyone implemented this before? Please share your ideas. Thank you very much in advance. 




The difficult part of a ranking method is smoothing the process over time, especially with a very deep record set (such as Accounts can be).  Because if you have multiple records over a period of time which, for example, all rank out to "2", eventually you may run out of space to describe the difference between 2 and 3, because you'll continually be using smaller increments.


You can use triggers to temporarily place records, so a new "2" might be "2.5" to properly be placed, and the next might be "2.75".  I would also, however, recommend, looking at batch and scheduled Apex to keep some sanity on the above.  So on a daily basis, Apex could make "2, 2.5, 2.75, 3" into 2, 3, 4, 5 and so on...  Obviously doing that may continually effect large record sets frequently.


A true ranking system isn't trivial by any means, so I would be sure on the use case/user needs before proceeding.  Do you need the ranking to control the data set in some way, or can you provide the user some kind of indication of where the account stands in relation (say a table of the 5 accounts above, or 5 account below, or a VF component which could do a simple COUNT() of Accounts greater/smaller).