You need to sign in to do that
Don't have an account?
Wilfredo Morillo 20
Multi-Picklist: Add or Remove value apex function
I created this function to add or remove selected values in a multipicklist. It works but I'm trying to simplify it. Any comments or suggestions are truly apriciated.
// This function returns an string with the values for a multipicklist after adding or removing an input Value. Public Static String MultipicklistUpdate(String currentValues,String inputValue,boolean addValue){ list<String> allValues = new List<String>(); boolean inputExist = false; String newValue = null; If (!(currentValues == '' || currentValues ==null)){ allValues = currentValues.split(';'); for(String value :allValues){ if(value == inputValue){ inputExist = true; if(addValue == true)newValue =+';'+ value; }else{ if(newValue==null){ newValue =+ value; }else { newValue = newValue +';'+ value; } } } } If(addValue == true && inputExist == false){ if(newValue == null){ newValue = inputValue; }else{ newValue = newValue+ ';'+inputValue; } } return newValue; }
I would put the current values into a map and then use the remove or put functions depending on your boolean