I have a Map<String, Object> idCollection.
Object accountIdObject = idCollection.get('accountId');
Doing this gets me a single string value. Now I am sure that accountIdObject is a String and have a requirement to add it to a List<String> accountId
Something like this is easily possible in java which would assign the single string to a new list -
List<String> accountId = Arrays.asList((String)accountIdObject);
What would be the best way for such initialization in apex ?
I have tried -
List<String> accountId = new List<String>{(String)accountIdObject}
;
which is giving an exception Illegal assignment from Object to List. Also I am sure that accountIdObject contains a string value which I have confirmed by doing a accountIdObject instanceof String
which returned true.
List
would only have more than one value? Or should it only have one value?