+ Start a Discussion
TheCustomCloudTheCustomCloud 

How to Dynamically pull Org Instance?

<apex:image url="https://c.cs7.content.force.com/servlet/servlet.ImageServer?id={!TD_Logo}&oid={!$Organization.Id}"/>

I remove all hardcoding but this one is giving me problems.  Is there a command to pull the org instance?

Best Answer chosen by Admin (Salesforce Developers) 
Ankit AroraAnkit Arora

Either you can do like this :

 

"/servlet/servlet.ImageServer?id=" or if you want to get the full URL then you can use the System.URL class introduced in summer 11.

 

// Get a file uploaded through Chatter.  
    
ContentDocument doc = [SELECT id FROM ContentDocument 
          WHERE title = 'myfile'];
// Create the link to the file.  
    
String fullFileURL = URL.getSalesforceBaseUrl().toExternalForm() +
   '/' + doc.id;
system.debug(fullFileURL);

 

http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_methods_system_url.htm

 

 

Thanks

Ankit Arora

Blog | Facebook | Blog Page

All Answers

gtindugtindu

any particular reason to hardcode the base url

<apex:image url="/servlet/servlet.ImageServer?id={!TD_Logo}&oid={!$Organization.Id}"/>

 

Ankit AroraAnkit Arora

Either you can do like this :

 

"/servlet/servlet.ImageServer?id=" or if you want to get the full URL then you can use the System.URL class introduced in summer 11.

 

// Get a file uploaded through Chatter.  
    
ContentDocument doc = [SELECT id FROM ContentDocument 
          WHERE title = 'myfile'];
// Create the link to the file.  
    
String fullFileURL = URL.getSalesforceBaseUrl().toExternalForm() +
   '/' + doc.id;
system.debug(fullFileURL);

 

http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_methods_system_url.htm

 

 

Thanks

Ankit Arora

Blog | Facebook | Blog Page

This was selected as the best answer
TheCustomCloudTheCustomCloud

Using "/servlet/servlet.ImageServer?id=" doesnt work.  The server you go to retrieve documents is different.

 

That new System.URL class did exactly what I needed, thanks!

 

In the class

public string docUrl = URL.getSalesforceBaseUrl().toExternalForm();

 

In the page

<apex:image url="{!docUrl}/servlet/servlet.ImageServer?id={!e.docImage__c}&oid={!$Organization.Id}"/>