I am not able to save below line of code in my class and I am not sure where am I going wrong.

<a href = "system.URL.getSalesforceBaseUrl()+'/'+app.Main_Offer_Name__c"> Click Here</a>

Erros says 'Arithmetic expressions must use numeric arguments'. Can someone please help me out with this one.

Also which base URL does system.URL.getSalesforceBaseUrl().toExternalForm() provide, classic or lightning?

Edit: Whole line of code for better understanding:

String htmlBody = '<b>Notification:</b></br></br>The Offer has been Approved at Stage'+app.Stage__c+'</br></br><b>Main-Offer Name: </b>'+app.Main_Offer_Name__r.Name+ '</br></br><b>Offer Link: </b><a href = "system.URL.getSalesforceBaseUrl()+'/'+app.Main_Offer_Name__c"> Click Here</a></br></br>';
  • Not sure where are you writing that code. Is it a Visualforce page? It doesn't seem to be an Apex class
    – Alba Rivas
    Nov 5 '20 at 13:32
  • @AlbaRivas It's actually Apex Class. I am basically constructing a body of email that I want to send and this is a part of that body. I want that recipients should be able to click on the link and it should redirect them to that record.
    – Rahul
    Nov 5 '20 at 13:35
  • But then you'd have to concatenate the HTML code with the variables computed by Apex, wouldn't you? Doing something like.... "<a href='" + system.getbase.... + "' > Click Here </a>". Maybe you can edit your question and add a bit more of your Apex class content.
    – Alba Rivas
    Nov 5 '20 at 13:38
  • @AlbaRivas I have added the whole body that I am trying to construct. Will that suffice?
    – Rahul
    Nov 5 '20 at 13:45

You are missing some quotes. Try this:

String htmlBody = '<b>Notification:</b></br></br>The Offer has been Approved at Stage'
                  + app.Stage__c
                  + '</br></br><b>Main-Offer Name: </b>'
                  + app.Main_Offer_Name__r.Name
                  + '</br></br><b>Offer Link: </b><a href="' + System.URL.getSalesforceBaseUrl()
                  + '/'
                  + app.Main_Offer_Name__c
                  + '"> Click Here</a></br></br>';
  • That worked, thank you. I just added toExternalForm() at the end to System.URL.getSalesforceBaseUrl().toExternalForm() and that solved my issue.
    – Rahul
    Nov 5 '20 at 13:58

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.