+ Start a Discussion
Harjeet Singh 13Harjeet Singh 13 

Create a field which calculate hash value based on multiple picklist field value same object

My requirement is to create a new field on Account object which will calculate hash value based on a multiple picklist field "Products" on account object and store in the newly created field in Account object.
I have one field called "Products" in account object which is a multi select picklist field with value: Baha,Vistafix,Codacs,Hybrid,Nucleus,CI ,Acoustic
Kindly help me how to achieve the same. I have no idea about hash and dont know how to proceed.
Any help would be greatly appreciated!
NagendraNagendra (Salesforce Developers) 
Hi Harjeet,

Apex codding is required for it. Create Account trigger, on its before insert/update action populate newly created field ProductsHash__c (Number type), that stores hashcode of Products field. Use System.hashCode method. Then get value of Products field and calculate hashcode with this method. Pseudo code will look like:
public void beforeInsert(Account newAcct){ AccountPopulator.populateProductsHash(null, newAcct); } public void beforeInsert(Account oldAcc, Account newAcc){ AccountPopulator.populateProductsHash(oldAcc, newAcct); }
Service class
public class AccountPopulator{ public static void populateProductsHash(Account oldAcct, Account newAcct){ if(oldAcct == null || oldAcct.Products__c != oldAcct.Products__c){ newAcct.ProductsHash__c = System.hashCode(acct.Products__c); } } }