function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Benjamin BolopueBenjamin Bolopue 

Dynamically rank Accounts based on volume.

I’ve been tasked with automatically ranking our Accounts based on the qty listed in a "projected volume" field. Any suggestions?

Thanks in advance!

Ben
magicforce9magicforce9
Hi,

By ranking Accounts I'm assuming you want to update the Rating(i.e the standard picklist field in accounts object) with one of the option depending on value in 'Projected Volume' field.

Now how does 'Projected Volume' gets updated...I mean does some inserts the value manually or is this a formula field/roll'up summary field ?

I think you can write a Workflow Field update to update the Rating field with the appropriate option when 'Projected Volume' changes.

Create a Workflow Rule on Account with the Evaluation Criteria as 'created, and any time it’s edited to subsequently meet criteria' and Rule Criteria as 'Projected Volume' not equlat to null AND 'Projected Volume' > minvalue AND 'Projected Volume' < maxvalue (minvalue & maxvalue is the range for which you'd like the Rating to hold a certain picklist value) and then add the Field Update Workflow Action and select the Appropriate picklist value. 

You'll have to create multiple Workflow rules, one rule for each picklist value that you have in Rating field.

Hope this helps, there is also also an alternative way to do it by adding a Trigger on Account object, but I prefer the non apex way.

Thanks,
Mohammed
Benjamin BolopueBenjamin Bolopue
Hi Mohammed,
Thanks very much for taking the time to respond in such detail! I'm actually looking for a method of "ranking" Accounts. (as to "rating" them)

Additionally, I'm only looking to "rank" our Top 100 Accounts. These Accounts are manually included on our Top 100 list via an "Is Top 100 Account" checkbox.

Thanks again for you input!

Ben
magicforce9magicforce9
Hi Ben,

I think you can do this via work workflow, just add the condition('Is Top 100 Account' equals to TRUE)  in Rule Criteria before checking the 'Projected Volume' value

Thanks,
Mohammed
Benjamin BolopueBenjamin Bolopue
As each of the 100 ranks is really a moving target, I don't thing creating Work Flow Rules (WFRs) for each of them wouldn do the trick.

Let's say the Account ranked 30th has a projected volume (PV) of 19K units, and the Account ranked 29th has a PV of 20K units, the WFRs would need dynamically evaluate the PV of all Accounts and assign a rank accordingly in order to promote the 30th ranked Account to 29th (or any other rank) upon PV value change. From what I understand, the only plausable solution would be to write some sort of trigger that would fire whenever a PV field is updated. But... alas... I know slightly less than nothing about writting triggers.

Thoughts?

Thanks,
Ben
magicforce9magicforce9
Hmmm..I guess we are tying to hit a moving target here. Here is a sample trigger code which might help(assuming Rating & Projected_Volume__c is the api names of the field but you can change it if its different)

-------------------------------------------------------------------------------------------
trigger accountRankings on Account(after insert, after update){

for(Account acc : trigger.new)
{
//checking if the Projected Value is changed
if(acc.Projected_Volume__c != Null && (trigger.isInsert || (trigger.newMap.get(acc.id).Projected_Volume__c != trigger.oldMap.get(acc.id).Projected_Volume__c))
{
break;
}
else return;
}

//I'm assuming that - we need to rank top 100 accounts by Projected Volume.
//if you need more accounts then change the row limit
List<Account> accountList = [Select Projected_Volume__c, Rating from Account ORDER BY Projected_Volume__c DESC Limit 100];
if(!accountList.isEmpty()){
Integer accountListSize = accountList.size() ;
for(Integer i =  0 ; i < accoutListSize; i++) 
{
accountList[i].Rating = accountListSize;
accountListSize -= 1;
}
update accountList;
}
}
Benjamin BolopueBenjamin Bolopue
I'm getting a "Error: Compile Error: unexpected token: '{' at line 7 column 0" whenever I save...
Greg EnderleGreg Enderle
Benjamin,
Did you ever resolve this?  I am facing a somewhat similar challenge and am hoping you were able to solve this and be willing to share some tips.
Thanks!
Alex_GroagAlex_Groag
Hi - Just wanted to bump this up.  We're facing the same issue.  There's a report we're constantly running offline because we can't don't know how to write the trigger within Salesforce.