You need to sign in to do that
Don't have an account?

When a contact is created/updated, get total score of all the UNIQUE roles that exist on all the contacts of the account.
Contact has a multi select custom field called Role__c which can have values (Surgeon;Nurse;First Assist;Admin;CSR). Account has a custom field called Total_Score__c which is a number field. Mapping table Role_Score__c looks like this Role__c Score__c
Surgeon 10
Nurse 5
First Assist 10
Admin 0
CSR 20
When a contact is created/updated, get total score of all the UNIQUE roles that exist on all the contacts of the account.
Ex: Account 1
Contact 1 with roles Surgeon;Admin
Contact 2 with roles CSR:Admin
On Account 1 we should store the value as (10 + 0 + 20 = 30) because we only have 3 unique roles.
Surgeon 10
Nurse 5
First Assist 10
Admin 0
CSR 20
When a contact is created/updated, get total score of all the UNIQUE roles that exist on all the contacts of the account.
Ex: Account 1
Contact 1 with roles Surgeon;Admin
Contact 2 with roles CSR:Admin
On Account 1 we should store the value as (10 + 0 + 20 = 30) because we only have 3 unique roles.
Hi Kirtan, here's a working trigger. This one should work for you just fine. Let me know if it helps you or not. All the best
Hi Kirtan, here's a better version of the trigger code. What I've done differently, is establish variables (lines 5 - 10 in the code below) that set variables to store the points assigned to each Role. The reason I've done this is because if the points will change in the future, you can easily go back into the code and adjust the points right there in those variables at the beginning, instead of trying to find the score assignments throughout the code.
I've also added the the scoring logic within the Account's Contacts loop (lines 40 - 61 in the code below).
As a final result you have a trigger that looks like this: