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 salesforcesupport@XXXX.com  <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
  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.

|improve this answer|||||
  • When i click on the hyperlink it does'nt navigate to the record. It gives an error ' Page Not Found: /0015C00000SmqusQAB ' – user4947 Dec 10 '19 at 21:14
  • Does that ID exist? Is there a spurious character before or after it? – David Reed Dec 10 '19 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>'; – user4947 Dec 11 '19 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()
|improve this answer|||||

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.