You need to sign in to do that
Don't have an account?
Richard Rodriguez 1
Trigger to create record/s based on selections made from a multi-select picklist
I was hoping somebody could help me with the code for a Trigger, or a Schedulable Class that can run after hours, and a Test Class (if applicable?!) for creating a record, or records, based on selections made from a multi-select picklist.
Okay, so this is what we're dealing with...
On a Contact record (eg. 003000000000001) there's a multi-select picklist field called Skill Codes (ts2__Skill_Codes__c) made up of various job skills (eg. 'Auto Electrician', 'Blast Crew', 'Blast Hole Driller', 'Bobcat Op', 'Boilermaker', etc.).
On a custom object called Short List (ts2__s_UserList__c) there are multiple records named for each of the Skill Codes (eg. a0D000000000001 = 'Auto Electrician', a0D000000000002 = 'Blast Crew', a0D000000000003 = 'Blast Hold Driller', a0D000000000004 = 'Bobcat Op', a0D000000000005 = 'Boilermaker', etc.).
Connecting the two objects is another custom object called Short List Link (ts2__s_UserListLink__c) which is made up of several records (eg. a0C000000000001, a0C000000000002, a0C000000000003, etc.) that only contain two fields, a Contact lookup field (ts2__r_contact__c) and a Short List lookup field (ts2__r_user_list__c).
And this is what needs to happen...
I have also thought about the possibility of deleting the Short List Link when a User REMOVES the matching Skill Code from the Contact record, but that's getting a little too complicated for what I need right now.
I would normally use Process Builder for something like this, but there are 78 options in Skill Codes multi-select picklist, so the process would be way too big.
I know practically nothing about coding, so fully coded answers would be greatly appreciated.
Thanks.
Okay, so this is what we're dealing with...
On a Contact record (eg. 003000000000001) there's a multi-select picklist field called Skill Codes (ts2__Skill_Codes__c) made up of various job skills (eg. 'Auto Electrician', 'Blast Crew', 'Blast Hole Driller', 'Bobcat Op', 'Boilermaker', etc.).
On a custom object called Short List (ts2__s_UserList__c) there are multiple records named for each of the Skill Codes (eg. a0D000000000001 = 'Auto Electrician', a0D000000000002 = 'Blast Crew', a0D000000000003 = 'Blast Hold Driller', a0D000000000004 = 'Bobcat Op', a0D000000000005 = 'Boilermaker', etc.).
Connecting the two objects is another custom object called Short List Link (ts2__s_UserListLink__c) which is made up of several records (eg. a0C000000000001, a0C000000000002, a0C000000000003, etc.) that only contain two fields, a Contact lookup field (ts2__r_contact__c) and a Short List lookup field (ts2__r_user_list__c).
And this is what needs to happen...
- User edits Contact record 003000000000001
- Updates Skill Codes to 'Blast Crew' and 'Boilermaker'.
- Saves the Contact record.
- [ Code works its magic ]
- Creates a Short List Link record a0C000000000001.
- Auto-assigns the Contact (ts2__r_contact__c) field to '003000000000001'.
- Auto-assigns the Short List (ts2__r_user_list__c) field to the matching record id for 'Blast Crew' > 'a0D000000000002'.
- Saves the Short List Link record.
- Creates a Short List Link record a0C000000000002.
- Auto-assigns the Contact (ts2__r_contact__c) field to '003000000000001'.
- Auto-assigns the Short List (ts2__r_user_list__c) field to the matching record id for 'Boilermaker' > 'a0D000000000005'.
- Saves the Short List Link record.
- COMPLETED.
I have also thought about the possibility of deleting the Short List Link when a User REMOVES the matching Skill Code from the Contact record, but that's getting a little too complicated for what I need right now.
I would normally use Process Builder for something like this, but there are 78 options in Skill Codes multi-select picklist, so the process would be way too big.
I know practically nothing about coding, so fully coded answers would be greatly appreciated.
Thanks.
For code implementation, you can engage a salesforce Architect/Accelerator(https://help.salesforce.com/articleView?id=000337601&type=1&mode=1) You need to check with your salesforce account executive on this.
To get started with writing triggers, please see
https://trailhead.salesforce.com/en/content/learn/modules/apex_triggers/apex_triggers_intro
https://help.salesforce.com/articleView?id=bi_edd_wb_trigger_native.htm&type=5
The below posts do not match your exact requirement but give an idea of similar implementations:
https://salesforce.stackexchange.com/questions/269718/trigger-to-create-multiple-records-based-on-multiselect-picklist-value
https://salesforce.stackexchange.com/questions/48173/can-a-trigger-be-created-to-take-the-chosen-multi-select-picklist-values-and-dis
https://jenwlee.com/2018/02/13/passing-multi-select-values-from-one-object-to-object/
https://douglascayers.com/2017/06/23/how-to-compare-multi-select-picklist-fields-in-flow-or-apex/
If this information helps, please mark this answer as best. Thank you