+ Start a Discussion

Trigger to count and check most frequent recurring value in a related list?

There are two objects account and contact. There is a picklist field on contact called service and a field on account called prefered service.
there can be n no of contacts for an account.
My requirement is
i have 5 contact records C1,C2,C3,C4,C5 under an account A1.
C1- is having service as plumber
C2- is having service as carpenter
C3- is having service as plumber
C4- is having service as gardenner
C5- is having service as plumber
once inserted/updated it should check which of the picklist values is having more no of occurance and  prefered service field of account should get updated with mostly used values as "Plumber"
How can i achieve that?