You need to sign in to do that
Don't have an account?
Nandhini S 3
How to split values in a field in a list
Hi Guys,
I have a field which has values separated by commas. I have queried this field and stored in a list. The list has only one record. How do I separate the values in the field?
I have a field which has values separated by commas. I have queried this field and stored in a list. The list has only one record. How do I separate the values in the field?
Please use the split method on the string - https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_methods_system_string.htm#apex_System_String_split
So if your
String str = 'abc,def';
str.split(',') wil result in ['abc','def'] a list of the values.
String addressFull = 'F-206, Daffodils, Magarpatta, Pune, India, 411028';
String[] address = addressFull.split(',');
String houseNumber = address[0];
String buildingName = address[1];
String streetName = address[2];
String cityName = address[3];
String countryName = address[4];
System.debug(houseNumber);
System.debug(buildingName);
System.debug(streetName);
System.debug(cityName);
System.debug(countryName);
Also please refer to this link:
https://www.infallibletechie.com/2020/03/string-split-method-in-apex-in.html
Please mark it as the best answer, if it helps in any way.
Thanks!