You need to sign in to do that
Don't have an account?
SFC7
Trying to Create Hyperlink in a trigger
Based on the business requirement I have to make text as a link in trigger and then I wanna retrieve/print that value in a standard page.
eg. string link = '<a href=/'+ accId +'>'+accName+ '</a>'
Please share your thoughts.
All Answers
HYPERLINK('/{!accountId}', {!account.Name}),{})
Thanks for your chain reply!
As i said i wanna make it through a trigger(After insert) because of auto populate in a standard salesforce VF page.
Hi,
Yes, You can write trigger :
Firstly Create Custom field on Account Object : Trigger_Populate_Link__c [Rich Text Area(256)]
After that write trigger like :
trigger accountTrigger on Account (before insert, before update) {
if(Trigger.isBefore && (Trigger.isUpdate || Trigger.isInsert)){
for(Account a : trigger.new){
a.Trigger_Populate_Link__c = '<a href=/'+ a.Id +'>'+ a.Name+ '</a>';
}
}
}
Thank you, I tried on this way and the result is just weird.
It displayed <a href=/AccounID>Account Name</a>.
Thank you in advance.
I appreciate if anyone have any thoughts on this.
1. Create a field and hold account Id in it using your current trigger.
2. Create a field and hold account Name in it using your current trigger.
3. Create a new formula field with formula :
HYPERLINK('/{!accountId}', {!account.Name}),{})
You can hide, first 2 fields from page layout if not required.
Thanks for your suggestion again, but here is what I'm looking for
e.g., ac.link__c = <a href=/'+ a.Id1 +'>'+ a.Name1+ '</a> \n <a href=/'+ a.Id2 +'>'+ a.Name2+ '</a>
I want to display those href links(more than one) in a standard page.
Try this -
ac.link__c = '<a href=''/'+ a.Id1 +'''>'+ a.Name1+ '</a>' + '\r\n' + '<a href=/'''+ a.Id2 +'''>'+ a.Name2+ '</a>
I have highlighted the changes in red.
Thank you...I did all the way that you mentioned and it displayed <a href=/a.Id>a.Name1</a>
<a href=/a.Id2>a.Name2</a>
instead of links.
Thank you in advance.
You need to change your field to type "Rich Text Area" in order to display hyperlinks - try creating a new rich text area field and populating it like this in the trigger. That should show up as hyperlinks.
Amego, You are thinking same as me :)...i did this too
nope!
I don't understand - I got this code to work in my org. Basically I created a trigger on the Account object, that was putting the HREF in a rich text field (rich text field, not long text field).
Are you trying to use the ID field in a "before insert" trigger ? If that is so, your href will be NULL, because the ID field is null before the object is actually created.
Hi,
I have tried this way it is working correctly..
Firstly Create Custom field on Account Object : Trigger_Populate_Link__c [Rich Text Area(256)]
After that write trigger like :
trigger accountTrigger on Account (before insert, before update) {
if(Trigger.isBefore && (Trigger.isUpdate || Trigger.isInsert)){
for(Account a : trigger.new){
a.Trigger_Populate_Link__c = '<a href=/'+ a.Id +'>'+ a.Name+ '</a>';
}
}
}
Is your senerio is different or you are writing trigger on different object... Please provide details?
links...btw, i achieved this on a different scenario.
Thanks to all folks :)
even i am searching for the method to Create Hyperlink in a trigger.
I was having the same issue.
What i found is that you need to give full url, with hostname in href.
With hostname (http://google.com)
Without hostname (google.com)
Your good suggestion worked for me...
Thanks again... :)
@sfc7
what is the solution. I have the same requirement.