All Ideas

Idea Details

Post an Idea
740  Points
Open
Idea has been posted. Give it an upvote or downvote.

Apex Enum parse from string

Apex & Visualforce

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");

Merge Idea · Flag

  • Upvotes
  • Downvotes

Ideas

Apps

from AppExchange

Questions

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.