I want to write an apex trigger action to remove a particular value from multi select picklist field based on some condition.How can I do this?
This is my trigger action:
public static void updateStopCom(map<Id, Account> accountOldMap, map<Id, Account> accountNewMap) {
for (Id accountId : accountNewMap.keySet()) {
Account newAccountValue = accountNewMap.get(accountId);
Account prevAccountValue = accountOldMap.get(accountId);
if ( (newAccountValue.Online__pc != prevAccountValue.Online__pc)){
if(newAccountValue.Online__pc == true){
newAccountValue.StopCom__c = ???; // how?
}
}
}
}
StopCom__c is my multi select picklist field.
Could anyone please help me to resolve this?
Best Answer
As multiselect picklist fields are stored as semi colon separated values, you will have to follow below steps to add/remove values to/from it.
List
list
list
back to semi colon separated values usingString.Join
methodThis is how your code should look like