Work.com
Leading Through Change with Data
COVID-19 Data Hub
COVID-19 Global Daily Tracker
Global Economy Data Track
Government Data Track
Healthcare Data Track
B-Well Together
Leading Through Change
Salesforce Care
Leading Through Change Blog
Trailhead Resources
AppExchange Resources
MuleSoft Resources
< Back to List
Daniel Ballinger
Apex Enum parse from string
Development (Apex, LWC & VF)
Currently in Apex converting from a string to an Enum item requires iterating all the values and comparing the .name() with the string. E.g. String soapTypeToMatch = 'Time'; Schema.SoapType soapTypeMatch = Schema.SoapType.anyType; for (Schema.SoapType st : Schema.SoapType.values()) { if (st.name() == soapTypeToMatch) { soapTypeMatch = st; break; } } Add a system method for converting from a string to the matching Enum item/value. E.g. Schema.SoapType st = Schema.SoapType.parse('Time'); .NET has a generic method to handle such conversions. DayOfWeek wednesday = (DayOfWeek)Enum.Parse(typeof(DayOfWeek), "Wednesday");
String soapTypeToMatch = 'Time'; Schema.SoapType soapTypeMatch = Schema.SoapType.anyType; for (Schema.SoapType st : Schema.SoapType.values()) { if (st.name() == soapTypeToMatch) { soapTypeMatch = st; break; } }
Schema.SoapType st = Schema.SoapType.parse('Time');
DayOfWeek wednesday = (DayOfWeek)Enum.Parse(typeof(DayOfWeek), "Wednesday");
Merge Idea · Flag
Flaviano Toledo - 8 months ago
DayOfWeek.valueOf('Wednesday')
Noel Light-Hilary - 1 year ago
Nic Edwards - 1 year ago
Pranay Jaiswal - 2 years ago
Alexey Lobanov - 2 years ago
Nathan Hinchey - 3 years ago
Paul Pervinkler - 4 years ago
Vance Kessler - 4 years ago
Daniel Ballinger - 5 years ago
Help us to keep IdeaExchange clean by pointing out overlapping ideas. We'll investigate your suggestion and merge the ideas if it makes sense.
Thanks for your merge suggestion. We will review it shortly and merge the ideas if applicable.
Salesforce takes abuse situations very seriously. Examples of abuse include but are not limited to posting of offensive language or fraudulent statements. To help us process your request as quickly as possible, please fill out the form below describing the situation. For privacy and security reasons, the final outcome of an abuse case may not be revealed to the person who reported it.
Thank you for your feedback. We take abuse seriously and will investigate this issue and take appropriate action.