A company XCorp recently integrated their salesforce instance to a subscription management system. XCorp has a requirement to convert values stored in a multi-select picklist to a list of strings. The company uses a custom lightning web component (lwc) with a multi picklist field for users to select account descriptions from a predefined set of values. As with multi picklist, the values are stored with ‘;’ as separator in the account description field.
XCorp requires all accounts to be synced with their subscription management system. The subscription management system has a limitation that it cannot accept ‘;’ in the account description but can accept a list of strings.
To resolve this limitation, the team at Xcorp has decided to send the account description as a list of string instead of values separated with ‘;’
Instructions:
1. If the account description is not empty, check for ‘;’ in the description
2. If account description contains ‘;’ split the string to a list and return it
Complete the given apex method to split the string separated by ‘;’ to a list of strings.
Example:
//accountDesc = Fast Mover;Growth Potential;Acquisition Target;High Value;Long-Term Partner;
List<String> accDescList = accountDetailsController.convertMultiPickList(String accountDesc);
//accDescList = [Fast Mover, Growth Potential,Acquisition Target,High Value,Long-Term Partner];
Note: This exercise is designed to introduce you to writing a simple apex method for splitting a string which contains ‘;’. Concentrate on implementing a solution using apex string methods. Feel free to validate your code by clicking the execute button.