+ Start a Discussion
uHaveOptionsuHaveOptions 

getting web URL of a lookup value.

Help on a formula to get the web url of a lookup value.

Example:
Contact Lookup = John Doe
URL Field= https://na16.salesforce.com/003FSV234233AAW

How can I achieve this?

Thanks

 
Best Answer chosen by uHaveOptions
Naval Sharma4Naval Sharma4
Hi Jon,

You just need to create a text field with hyperlink on your object and try this as formula to obtain link.

HYPERLINK("https://XXX.salesforce.com/" & LookupFieldName.ID, LookupFieldName.FirstName & " " & LookupFieldName.LastName, "_self")

Replace the XXX with your salesforce server name and LookupFieldName with the name of contact lookup field name. 


See if this works.

All Answers

Mahesh DMahesh D
Hi Jon,

Please use the below sample code:
 
trigger ContactTrigger on Contact (before insert, before update) {
    for(Contact c: trigger.new) {
        if (c.AccountId != null) {            
            c.Test_Lookup_URL__c = System.URL.getSalesforceBaseURL().toExternalForm()+'/'+c.AccountId;
        }
    }
}

I also verified the above code in DE environemtn and it looks good.

Please do let me know if it helps you.

Regards,
Mahesh
Naval Sharma4Naval Sharma4
Hi Jon,

You just need to create a text field with hyperlink on your object and try this as formula to obtain link.

HYPERLINK("https://XXX.salesforce.com/" & LookupFieldName.ID, LookupFieldName.FirstName & " " & LookupFieldName.LastName, "_self")

Replace the XXX with your salesforce server name and LookupFieldName with the name of contact lookup field name. 


See if this works.
This was selected as the best answer
uHaveOptionsuHaveOptions
That work!
 
Kristopher TurekKristopher Turek
I have created the following link and am getting errors - please help
HYPERLINK("https://xxx.salesforce.com/"&Id,Opportunity_ID__c + "-" + Account.Name + "-" + Name,"_self")

The link turns into this
https://xxx.salesforce.com/%EF%BB%BF0060e00001qN2jU