0

I am looking to add a URL into a text field in a similar fashion to the way you can add a HYPERLINK in a Formula (Text) field. I have already taken a look at the information in How to give a URL field Link text and this is currently how I am getting a hyperlink. Currently the hyperlink formula looks something like this:

HYPERLINK("https://a-web-address-i-use.com/browse/" & Custom_Field__c , Custom_Field__c )

This HYPERLINK gives me something that looks like this somedata which works. However users need to be able to enter multiple items into the Custom_Field__c.

I was hoping to use the System.Url Class, however, I seem to be breaking something here.

I have created the following trigger to attempt to add the URL but it is not working.

trigger textLinkChangedTrigger on Case (before update)
{
    for (Case c : Trigger.new)
    {
        System.debug('This is the start of the textChangedTrigger event');
        if (c.text__c != null)
        {
            Case caseOld = Trigger.oldMap.get(c.Id);
            String text = c.text__c;
            List<String> Tickets = text.split(',');
            if (c.text_Link_Replacement_Rich__c == caseOld.text_Link_Replacement_Rich__c)
            {
                c.text_Link_Replacement_Rich__c = '';
            }
            for (String t : Tickets)
            {
                // Will use this to trim the whitespace then remove all spaces from the strings
                t = t.trim();
                t = t.replaceAll('(\\s+)', '');
                System.debug(t);
                System.Url j = System.Url('https://text.mywebsite.com/browse/' + t, t );
                System.debug('The current text Link is: ' + c.text_Link_Replacement_Rich__c + ' The added text link is: ' + j);
                c.text_Link_Replacement_Rich__c = c.text_Link_Replacement_Rich__c + j;
            }
        }
    }
}

I receive the error:

Method does not exist or incorrect signature: void Url(String, String) from the type System.

Any assistance or information would be greatly appreciated

This is the current Formula for the Link Field

This is how it is viewed on the case page

Note these Images are from a private sandbox and not the production sandbox, however the settings match across. Just can't show production for privacy

キリトくん

6
  • 2
    What do you mean it doesn't work? Do you get an error? what happens with this code? why isn't it what you need?
    – Nick C
    Commented Jul 28, 2021 at 14:50
  • When iterating is the goal to create multiple full urls? Or do you just want to add the multiple t variables to the end of text.mywebsite.com/browse Commented Jul 28, 2021 at 15:07
  • @NickCook My appologies, I thought I included the error. The error I get is Method does not exist or incorrect signature: void Url(String, String) from the type System. Through from my understanding there should be a constructor in System.Url as shown by URL Constructors The following are constructors for URL. Url(context, spec) Creates a new instance of the URL class by parsing the specified spec within the specified context.
    – キリト
    Commented Jul 28, 2021 at 21:32
  • @ZackWalton You are correct, The iteration is so that I can create multiple full URLs. Again I found I could do this with an IF statement and the HYPERLINK however I needed 1 IF statement for every iteration as there was no loop in formulas
    – キリト
    Commented Jul 28, 2021 at 21:35
  • @キリト Can you provide an example of what the output should look like?
    – Nick C
    Commented Jul 29, 2021 at 2:55

1 Answer 1

0

So I ended up switching out the text field for a Rich Text Field, Then I completed the following.

trigger textLinkChangedTrigger on Case (before update)
{
    for (Case c : Trigger.new)
    {
        // System.debug('This is the start of the textChangedTrigger event');
        if (c.text__c != null)
        {
            Case caseOld = Trigger.oldMap.get(c.Id);
            String text = c.text__c;
            List<String> Tickets = text.split(',');
            if (c.text_Link_Replacement_Rich__c == caseOld.text_Link_Replacement_Rich__c)
            {
                c.text_Link_Replacement_Rich__c = '';
            }
            for (String t : Tickets)
            {
                // Will use this to trim the whitespace then remove all spaces from the strings
                t = t.trim();
                t = t.replaceAll('(\\s+)', '');
                // System.debug(t);
                String j = '<a href="https://text.mywebsite.com/browse/' + t + '">'+ t + '</a>';
                // System.debug('The current text Link is: ' + c.text_Link_Replacement_Rich__c + ' The added text link is: ' + j);
                c.text_Link_Replacement_Rich__c = c.text_Link_Replacement_Rich__c + ', ' + j;
            }
        }
    }
}

Once the code was implemented I simply added the field as a `lightning:formattedRichText' field in a component which is shown at the top of the case and... It works!

The only final annoyance is that when you show the rich text field in as a column in the cases overview console page you are no longer able to access this as a link from the cases page and if you want to access the page as a link you need to enter the case itself and then you will have the options presented at the top of the list.

All in all I am satisfied with how this works for the time being. Thank you to everyone who assisted me, made edits to my posts and was along for the ride on the overall journey. I appreciate the time and effort. Please feel free to provide feedback or additional information if you think it is relevant to the overall solution.

キリト

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .