1
       Account acc = [Select Id,Name,Owner.Name FROM Account WHERE Id =: accId];
       String HtmlBody='Attention Data Analyst,<br><br>';
       HtmlBody+='Please verify the Account: ' + '</b> + acc.Name+ </b> <br><br>';

       HtmlBody+='The link to the Account is : <a href="'+System.URL.getSalesforceBaseUrl().toExternalForm()+'/'+acc.Id+'">Click Here</a> <br><br>';
       HtmlBody+='For questions about the Account contact the Account Owner ' +acc.Owner.name+' <br><br>';
       HtmlBody+='For Salesforce questions contact [email protected]  <br>';

I have two questions

  1. How to display the value of 'acc.name' in bold ?

    HtmlBody+='Verify the Account: ' + acc.Name+ '<br><br>'; 
    
  2. link is different in execute anonymous and the email that i get. Why ?

    Execute Anonymous :
    system.debug('--'+System.URL.getSalesforceBaseUrl().toExternalForm());

    // URL is correctly displayed

     https://xxx--Dev2.cs62.my.salesforce.com
    

    Apex:

    // URL is

    https://dev2-xxx.cs62.force.com/'<recordid>'
    

Can some one please suggest what changes I need to make to get the correct URL?

2 Answers 2

2
  1. Your HTML is wrong. </b> + acc.Name+ </b>: you have two closing tags, and no opening <b> tag.

  2. Both domain names are correct. Salesforce URLs may take a variety of forms based on the context; for example, my developer edition goes by <my domain>-dev-ed.na82.force.com when it is displaying a Classic application, and <my domain>-dev-ed.lightning.force.com when in Lightning.

3
  • When i click on the hyperlink it does'nt navigate to the record. It gives an error ' Page Not Found: /0015C00000SmqusQAB ' Dec 10, 2019 at 21:14
  • Does that ID exist? Is there a spurious character before or after it?
    – David Reed
    Dec 10, 2019 at 23:25
  • Yes, that Id exists. Doesn't seem like there is a spurious character around it. But I will recheck. HtmlBody+='The link to the Account is : <a href="'+System.URL.getSalesforceBaseUrl().toExternalForm()+'/'+acc.Id+'">Click Here</a> <br><br>'; Dec 11, 2019 at 8:38
1

enter image description here

Per Docs, another option is that you can get the domain URL to appropriately link records in this type of situation and it should work in both contexts (Lightning and Classic).

HtmlBody+='The link to the Account is : <a href="'+System.getOrgDomainURL()+'/'+acc.Id'">Click Here</a> <br><br>';System.getOrgDomainURL()
1

You must log in to answer this question.

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