function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
jucuzoglujucuzoglu 

How do I pass a static URL to a class property?

I have the following Class

 

    public class linkListItem {
        public string title {get;set;}
        public url value {get;set;}
        
        public linkListItem(string gsTitle, url gsValue)
        {
            title = gsTitle;
            value = gsValue;
        } 
        
    }   

 And I want to create a list of this new linkListItem and add elements to the list. Passing the string in the constructor is easy, but I can't figure out how to pass the URL.

 

I'm using code similar to:

 

mylinkListItemList.add(new linkListItem('My Link Title','/apex/somepage?id=' + myObj.Id);

The problem is it sees the constructor as (String),(String) rather than (String), (Url).

 

How do I pass the second part as a URL?

Starz26Starz26

I believe that all URLs are strings, maybe this will work for you

 

public class linkListItem {
        public string title {get;set;}
        public string value {get;set;}
        
        public linkListItem(string gsTitle, string gsValue)
        {
            title = gsTitle;
            value = EncodingUtil.urlEncode(gsValue, 'UTF-8');
        } 
}