Create URL to static resource image. Need quick answer ... swamped and can't think. :S

  • 2
  • Question
  • Updated 5 years ago
  • Answered
I know all the resources are in here but I don't have time. :/

Basically need to produce a URL for my Conga template to bring in an image.

https://na15.salesforce.com/resource/1421083611000/RECON__wi_wind.png

https://na15.salesforce.com/ dynamic to org

resource/ is static

1421083611000 is ???? not sure where this comes from. The resource ID is 081i0000000XWEM. I'm wondering if there is a way to get 1421083611000.

RECON__wi_ is static

wind is from field RECON__Icon__c

.png is static
Photo of Pat Vachon

Pat Vachon, Champion

  • 45,026 Points 20k badge 2x thumb

Posted 5 years ago

  • 2
Photo of Ben Hubbard

Ben Hubbard

  • 12,710 Points 10k badge 2x thumb
Hi Pat,

The number you see there is the unix timestamp for the date that this resource was last changed.  It is actually optional.  It's only used as a "cache buster" to helping your browser not use a cache when the file is updated.

Option 1: Don't use that number at all.

https://na15.salesforce.com/resource/RECON__wi_wind.png
This should work just fine.  However, your browser will try to use its cache whenever it can.  This is probably good for an image that does not change.

Option 2: Make up a number and hardcode it.

https://na15.salesforce.com/resource/1337/RECON__wi_wind.png
This will work fine as well, however it will exhibit the same caching behavior as Option 1.

Option 3: Figure out the last modified timestamp of the resource and use it

https://na15.salesforce.com/resource/1421083611000/RECON__wi_wind.png
This option has the most desirable caching behavior in my opinion.

Option 4: Use the current timestamp for "right now".

https://na15.salesforce.com/resource/1421086698000/RECON__wi_wind.png

This will never be cached and will always be requested from the server.  Seems kinda wasteful to me.  But there are some times where this is needed.
(Edited)
Photo of Pat Vachon

Pat Vachon, Champion

  • 44,756 Points 20k badge 2x thumb
Awesome. Good to know bout the timestamp. That works.


How about getting the "na15.salesforce.com/" part?
Photo of Ben Hubbard

Ben Hubbard

  • 12,710 Points 10k badge 2x thumb
Can't you just use a relative link instead of absolute?

/resource/RECON__wi_wind
Photo of Pat Vachon

Pat Vachon, Champion

  • 44,756 Points 20k badge 2x thumb
I need it to be absolute. Can I get this from javascript? Similarly to mustache CurrentSiteUrl ?
Photo of Pat Vachon

Pat Vachon, Champion

  • 44,756 Points 20k badge 2x thumb
Photo of Pat Vachon

Pat Vachon, Champion

  • 44,756 Points 20k badge 2x thumb
I suppose I can also hack it out of the address bar. How is that done?

This method can also be an issue as the Site URL will be different from a skuid page than a static resource.
https://skuid.na15.visual.force.com/apex/skuid__ui?page=Job_Detail_Master&id=a00i000000VSPiyAAH
vs
https://na15.salesforce.com/resource/1421083611000/RECON__wi_wind

So I basically need the salesforce server in which org is on. "na15" in this case.

This can be alternatively setup as part of the app in a "Custom Setting". This is beyond something I've ever done, but can apex be run to set this setting in custom setting such that the formula field points to the right static resource?
(Edited)
Photo of Pat Vachon

Pat Vachon, Champion

  • 44,756 Points 20k badge 2x thumb
If upon installing an app from the appexchange some apex can be used to update a system setting, then BAM!





Photo of Zach McElrath

Zach McElrath, Employee

  • 53,864 Points 50k badge 2x thumb
You can get the Instance by querying the Organization object, and grabbing the InstanceName field off it, then you could use the instance in merge syntax like this:

{{$Model.Org.data.0.InstanceName}}

Photo of Zach McElrath

Zach McElrath, Employee

  • 53,864 Points 50k badge 2x thumb
So the end result would be something like:

https://{{$Model.Org.data.0.InstanceName}}.salesforce.com/resource/RECON__wi_wind
Photo of Pat Vachon

Pat Vachon, Champion

  • 44,756 Points 20k badge 2x thumb
That works too. Not sure what I like better now. Formula fields are better cause then there's is less code to manage. But then I have to set the "na15" via Custom Setting upon install using Apex.
Photo of Pat Vachon

Pat Vachon, Champion

  • 44,756 Points 20k badge 2x thumb
The result needs to be stored in the object for Conga to get to it. I could update the field using javascript, but I think that it is easier to manage this standard salesforce.

This is assuming that everything between https://    &     /resource/RECON__wi_wind can be acquired with APEX upon install and populate a custom setting with this value.