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
Daniel Peaper 8Daniel Peaper 8 

Where am I going wrong building a string for a VF page?

I have inherited the following code in a vfp controller class with a hard coded url. I decided to modify it:-

String customDomainName = 'https://toptechservice—partial-c.documentforce.com/sfc/dist/version/renditionDownload?rendition=ORIGINAL_Jpg&versionId=';

Integer index = DistributionPublicUrl.IndexOf('/a/',0);

String strSubString = DistributionPublicUrl.substring(index);

customDomainName = customDomainName + ContentVersionId + '&operationContext=DELIVERY&contentId=' + ContentDocumentId + '&page=0&d=';

customDomainName = customDomainName + strSubString + '&oid=' + orgId + '&dpt=null&viewId=';

system.debug('customDomainName: '+customDomainName);
       
I decided to modify it using URL.getSalesforceBaseUrl() as follows:

String orgDomain = URL.getSalesforceBaseUrl().getHost();

String orgURL = orgDomain.replace('visual','document');

String customDomainName = 'https://'+orgURL+'/sfc/dist/version/renditionDownload?rendition=ORIGINAL_Jpg&versionId=';


Depite both versions appearing identical in the Debug log only the hard-coded version works. When I view the vfp in the browser I can see that the string passed by my modified code has it's domain address changed to the Site URL. The string passed by the hard-coded version is not changed and hence works.

I just want to understand.

ANUTEJANUTEJ (Salesforce Developers) 
Hi Daniel,

The problem might be with the url itself did you try a different method to get the correct url to check with the rest of the code?

Regards.
Anutej