How can you use a relative URL for an image file inside documents vs hard coding the document ID in HTML?

I have an org to spin off templates that use images with the src linked to the document ID, like so src="/servlet/servlet.ImageServer?id=123ABC&oid=456XYZ/" but the problem is when I create a spun org, the images are broken because the id and org id are different.

Is there a more relative way of linking the document src via HTML? something like src="/servlet/servlet.ImageServer?name=ImageFile" ?

It's outside Visualforce unfortunately so I can't apex it.

If this is impossible, please let me know too, and why. Alternatives also welcome, like how to use static resources as user-friendly link in HTML (not Visualforce).

  • Yes, it is possible to do this in the static resource. You need to maintain a zipfile with images. Then in your VG page, you can have something like this <link rel="apple-touch-icon" sizes="57x57" href="{!URLFOR($Resource.ZipFile", 'mytouch-icon-57x57.png')}" />
    – abhi
    Apr 21, 2016 at 21:14
  • More information here - https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_compref_additional_page.htm
    – abhi
    Apr 21, 2016 at 21:16
  • You might think about creating an object that store links to all of your images in, then install the object when you set up a new org. All you'd need to do then is change the orgId. Perhaps some kind of formula field or script could populate the OrgId for you. Never tried it, but it sounds like something you could do. Don't know enough about your use case to say.
    – crmprogdev
    Apr 21, 2016 at 21:45

1 Answer 1


My own answer. Requires some manual re-uploading of assets.

Step 1 - use Static Resources instead of Documents. Static Resource assets maintains namespace when spinning off new orgs. (Theoretically anyway, untested as of right now).

Step 2 - Upload images to Static Resources, like "ExampleImage". Zipped folders don't seem to work.

Step 3 - Within HTML (not visualforce), the src can be set to the name of the Static Resource. The resulting URL needs to resolve to "https://yourdomain.com/resources/ExampleImage".

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .