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
KaityKaity 

Need Dynamic Link

I'm sending mail. And while doing so, I have given a link as below:

 

 CaseNotificationmail.setPlainTextBody('Your case Status: ' + c.CaseNumber + 'To view your case <a href=https://na1.salesforce.com/' + c.Id); 

 

But, I think, this a not a good practise because Salesforce may change the instance from n1 to n2 or n3. At that time this code will fail.

 

Is there any way to make it dynamic?

 

-Kaity

Best Answer chosen by Admin (Salesforce Developers) 
liron169liron169

Try:

 

'Your case Status: ' + c.CaseNumber + 'To view your case <a href=https://' + System.URL.getSalesforceBaseUrl().getHost() + '/'+ c.Id);

All Answers

liron169liron169

Hi,

 

You can use

System.URL.getSalesforceBaseUrl().getHost()

 

it will return you:

'na1.salesforce.com'

KaityKaity

But , what would be the syntax , if you want to write the following code:

 

'Your case Status: ' + c.CaseNumber + 'To view your case <a href=https://na1.salesforce.com/' + c.Id); 

liron169liron169

Try:

 

'Your case Status: ' + c.CaseNumber + 'To view your case <a href=https://' + System.URL.getSalesforceBaseUrl().getHost() + '/'+ c.Id);

This was selected as the best answer
KaityKaity

You are absolutely correct. Big thanks..

 

-Kaity