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
MohaMoha 

Getting the URL for the current organization instance at runtime

Hello I need to retrieve the Url of the current Organisation at runtime i used this url but it doesn't retrieve the right url :

 

https://'+ApexPages.currentPage().getHeaders().get('Host')

thanks for the help

MohaMoha

thanks for the reply, i've already used this but it doesn't solve my problem, i need in Portal site to call a document Text through apex Class

so when i use the : 

URL.getSalesforceBaseUrl().toExternalForm() + '/servlet/servlet.FileDownload?file='+lstDocument[0].Id;
return strDocUrl;

it return SiteInstance/servlet/the rightfile   but it's not shown on the Site 

 

but if i hardcode the url as example : https://c.eu10.content.force.com/servlet/... it shows the Document on the Site

 

so i don't know how to get the Second Url Dynamically 

thanks for the help

kiranmutturukiranmutturu
did u try with url.getFileFieldURL
like
String fileURL = URL.getFileFieldURL( lstDocument[0].Id ,'AttachmentBody');
return fileURL;
MohaMoha

i get this Error, i  searched in the book and i used the correct method but i get this error : Method does not exist or incorrect signature: URL.getFileFieldURL(Id, String) at line 33 column 27

kiranmutturukiranmutturu
may i know what you are filling in id and string exactly....?
MohaMoha

practicaldetail = 'PracticalDetail';
List<Document> lstDocument = [Select Id,Name,LastModifiedById from Document where Name = :practicaldetail limit 1];

 

String fileURL = URL.getFileFieldURL( lstDocument[0].Id ,'PracticalDetail');
return fileURL;

kiranmutturukiranmutturu
change like this and try
List<Document> lstDocument = [Select Id,Name,body,LastModifiedById from Document where Name = :practicaldetail limit 1];

String fileURL = URL.getFileFieldURL( lstDocument[0].Id ,'body');
MohaMoha
unfortunately it's not working the Same Error !!