How to get base url in Visualforce?

{!$Site.BaseUrl} is used to get base url in Visualforce.

Sample Code;

Visualforce Page:

<apex:page controller="Sample" sidebar="false">
    <apex:repeat value="{!listAcct}" var="a">
        <a href="{!$Site.BaseUrl}/{!a.Id}" target="_blank">{!a.Name}</a><br/>
    </apex:repeat>

</apex:page>

Apex Controller:

public class Sample {
    
    public List < Account > listAcct {get;set;}
    
    public Sample() {
        listAcct = [ SELECT Id, Name FROM Account ];
    }
    

}

Output:


Cheers!!!

No comments:

Post a Comment