I am trying to Convert text data type to Hyperlink Can Anyone help me on this below is the code i am trying

trigger EventTrigger on Event (before insert, before update) {

    if(Trigger.isBefore && (Trigger.isUpdate || Trigger.isInsert)){
        for(Event a : trigger.new){   

            a.Location = '<a href='+ a.Location +'></a>';



You can only create hyperlinks in fields that support it (they must be Rich Text Fields). As such, you're only going to get HTML in your Location field, as it is a normal Text field.

  • since i am perfomimg this trigger on event object i am unable to change field type.is there any other way to achieve this – yesh Apr 20 at 4:51

sfdcfox's answer about needing it to be a rich-text field is correct.

If you do change the field type though, your trigger would still not work for two reasons:

  • The value you're setting for the href attribute is not contained in double quotes
  • You're not checking to see if Location is already a link (any subsequent edit would make your Location be <a href=<a href=some.link>>)

While you could do this with a trigger, I don't think it's the right tool for the job here. At least not with the information you've given us so far. A workflow rule to set to fire only when the record changes to subsequently meet the criteria (with the criteria being that Location does not contain <a href=) and a field update could take care of this just fine.

You should also be able to create a before save record-triggered flow to accomplish the same thing as a workflow + field update (but it runs a little faster and because it's before-save, doesn't cause before/after update triggers to run again).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.