1

I currently managed to display some images(from salesforce Documents folder) on an extracted Excel sheet from Salesforce but I have hard coded the document Ids. So this might not work after creating package and after installing to different orgs.

I'm looking for a way to get the document Ids without hard coding them. Is there any way doing this ?

Apex Code:-

            movementDirUp = System.URL.getSalesforceBaseUrl().toExternalForm().replace('https','http')+'/servlet/servlet.ImageServerid=015240000005U3V&oid='+UserInfo.getOrganizationId();
            movementDirDown = System.URL.getSalesforceBaseUrl().toExternalForm().replace('https','http')+'/servlet/servlet.ImageServer?id=015240000005U3T&oid='+UserInfo.getOrganizationId();
            movementDirRight = System.URL.getSalesforceBaseUrl().toExternalForm().replace('https','http')+'/servlet/servlet.ImageServer?id=015240000005U3U&oid='+UserInfo.getOrganizationId();
            //Map to display images
            mapClimateMovement = new Map<String, String>{'climate_up_arrow' => movementDirUp , 'climate_down_arrow' => movementDirDown , 'climate_right_arrow' => movementDirRight.toLowerCase()};

Visualforce Code:-

<apex:image value="{!IF(CONTAINS(reportRow.parentInfo[field],'Up'),mapClimateMovement['risk_climate_up_arrow'],'')}"  rendered="{!CONTAINS(reportRow.parentInfo[field],'Up')}" />
                                <apex:image value="{!IF(CONTAINS(reportRow.parentInfo[field],'Down'),mapClimateMovement['risk_climate_down_arrow'],'')}" rendered="{!CONTAINS(reportRow.parentInfo[field],'Down')}" />
                                <apex:image value="{!IF(CONTAINS(reportRow.parentInfo[field],'Level'),mapClimateMovement['risk_climate_right_arrow'],'')}" rendered="{!CONTAINS(reportRow.parentInfo[field],'Level')}"/>
  • Could you use a static resource instead? – Girbot Apr 16 '15 at 15:02
  • No, currently everything is referenced via Documents in the product. – Tinkerbell Apr 16 '15 at 15:04
2

You can use something like this

List<String> lstDocNames; //Populate list with document names
Map<String, id> mapDocs; 

public void getDocuments(){
    mapDocs = new Map<id, String>();
    for(Document d: [Select Id from Document d where d.DeveloperName in :lstDocNames]){
        mapDocs.put(d.name, d.id); 
    }
}
| improve this answer | |
3

You can perform a query on the document object. Something like this:

public Document doc;

public void setDocument(){
    this.doc = [Select Id from Document d where d.DeveloperName = 'DocumentUniqueName']
}

public string DocId {
    get {
        return doc.id
    }
}

This requires that you know the unique name assigned to the document. This will be the same in every instance you install your package

Now you can make a property that returns the Id of this document object so that you can reference it in your servlet urls.

Sorry for terrible formatting on my cell phone..

| improve this answer | |
  • I have to display different Document images as given in my Apex code so I want to use one query to retrieve all of them and then reference from it. Don't I have to create a map to match the Id of the Document and the Document Name ? – Tinkerbell Apr 16 '15 at 15:21
  • Yes, you can retrieve multiple documents by modifying code provided above and create a map to maintain mapping of document name and id – Anshul Apr 16 '15 at 15:23
  • @Anshul can you please provide me an example or a code snippet ? – Tinkerbell Apr 16 '15 at 15:26
0

to retrieve the Id from the Map instead of hard coded Id, used the following line. movementDirUp = System.URL.getSalesforceBaseUrl().toExternalForm().replace('https','http')+'/servlet/servlet.ImageServer?id='+residualDocs.get('Climate_Up_Arrow')+'&oid='+UserInfo.getOrganizationId();

| improve this answer | |

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.