You need to sign in to do that
Don't have an account?
Greg Enderle
Update ranking dynamically based on field value
I have a custom object "Quota", and am attempting to update a custom field "Rank" based on the ranking of quota records via the value in the field "Amount over Quota". For example, the quota record with the largest value in "Amount over Quota" would need to have the "Rank" set at 1, and so on.
I am struggling mightily with writing a trigger. Anyone willing to lend a hand? I have a total of 4 rankings that need to be updated in this way, but if I can get the first one done I'm sure I can figure out how to get the others done as well.
Thanks!
I am struggling mightily with writing a trigger. Anyone willing to lend a hand? I have a total of 4 rankings that need to be updated in this way, but if I can get the first one done I'm sure I can figure out how to get the others done as well.
Thanks!
You will need to create triggers on the Quota object for after insert, update and delete to maintain the rank value.
Example:
List<Quota__c> quotas = [SELECT Id FROM Quota__c ORDER BY Amount_Over_Quota__c DESC]
Integer rank = 1;
for(Quota__c quota : quotas)
{
quota.Rank__c = rank;
rank++;
}
update quotas;
Depending on the record volumes you may want to consider async apex to maintain the ranks.
Hope that gives you something to work on,
Richard.