In Salesforce, When creating a custom field of type URL
, what apex variable type do I use to store that in my controller?
2 Answers
Other than String
there is no easy data type can store such characters. So, an obvious answer is String
.
String is the only data type which have capability to store all URL characters. And from the accessibility point of view String is the easiest data type to get and process.
The next powerful data types are Blob
and Object
but String
does everything which a URL type needs.
Perhaps you may have some deep logic to ask this question? I will be happy to answer.
-
Depending on what you're going to do with it, a PageReference type may also be interesting. Commented Feb 16, 2015 at 23:00
It has always been my practice to store URL's as a type String as most of the returns when you call something like URL.getSalesforceBaseUrl() returns a string and strings are most commonly used to be passed into URL constructors.
https://www.salesforce.com/us/developer/docs/apexcode/Content/apex_methods_system_url.htm