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
Harjeet Singh 13Harjeet Singh 13 

Create a field to calculate hash value based on multiple picklist field value

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 new field which is created.
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,

Please find the suggested workaround as suggested in stack exchange community.

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 the 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); } } }
Hope this helps.