Ever need to update Salesforce records that have multi-picklists without fear of overriding the existing data in those pick lists? Here’s a simple solution for you.

In my example below we’ll assume we have a Salesforce multi-picklist called Product_Interest__c on the Contact object.

Create a new custom text field on the Contact object to capture the data to be imported. I recommend labeling the field the same as the multi-picklist field name plus “import”. So in our example, that would be Product_Interest_Import__c. This puts the fields alphabetically next to each other when using your import tool making it easy to remember NOT to import data into the multi-picklist field.

Next create a Contact Before Update trigger and place the following code in the trigger (modifying the field names to match your fields):

for (Contact c: trigger.new) {
    // update Product_Interest__c multi-picklist if a new value is being imported
    string pl = c.Product_Interest__c;

    if (c.Product_Interest_Import__c != null) {
        string pli = c.Product_Interest_Import__c.trim();
        if (pl == null) {
            pl = pli;
        } else {
            if (pl.contains(pli)) { // do nothing
            } else {
                 pl = pl + ';' + pli;
            }
        }

        // reset the import field to empty so it doesn't attempt reprocess the import data
        c.Product_Interest_Import__c = null;
    }

    // set the multi-picklist to their new value
    c.Product_Interest__c = pl;
}

When you import your data, use your new Import (product_Interest__c) field. The trigger reads then import field, checks the multi-picklist field to see if it exist, if it doesn’t then in appends the import field into the Salesforce multi-picklist field.

Pretty simple and makes the import so much easier.

Terry Miller
Terry has spent over 20 years focused on business leadership and information technology. As an independent consultant, he enjoys working with a variety of customers to help them solve business problems using the Salesforce® platform. His ability to quickly identify bottlenecks and provide understandable solutions has gained him the trust of his customers. If you're looking for expert guidance on your next Salesforce® project, click here to contact Terry today.

2 Comments

  1. Pingback: Gregory Smith

Leave a Reply

Your email address will not be published.

*