You need to sign in to do that
Don't have an account?
Scott.M
Using URLFOR in apex with dynamic components
Does anyone know of an equivalent to URLFOR in Apex. We now have dynamic components that can be initialized in apex. For example if you wanted to initialize the stylesheet component you could do this:
Apex.Component.Stylesheet customstyle = new Apex.Component.Stylesheet();
customstyle.value = '/mystyle.css';
This is great but I want to initalize the component to use a static resource stored in a zip file. In visualforce that's easy using the URLFOR() function. Is there anyway to acheive the same functionality in Apex?
Thanks!
Scott
you can try this:
Component.Apex.Stylesheet customstyle = new Component.Apex.Stylesheet();
customstyle.value = URL.getSalesforceBaseUrl().toExternalForm() + '/resource/MobileCSS';
system.debug('customstyle.value is ' + customstyle.value);
MobileCSS is the resource name.
If it is inside the folder then use like this
customstyle.value = URL.getSalesforceBaseUrl().toExternalForm() + '/resource/MobileCSS/my.css';
All Answers
you can try this:
Component.Apex.Stylesheet customstyle = new Component.Apex.Stylesheet();
customstyle.value = URL.getSalesforceBaseUrl().toExternalForm() + '/resource/MobileCSS';
system.debug('customstyle.value is ' + customstyle.value);
MobileCSS is the resource name.
If it is inside the folder then use like this
customstyle.value = URL.getSalesforceBaseUrl().toExternalForm() + '/resource/MobileCSS/my.css';
thanks, it actually works with just the relative url /resource/name/path :)
yes I agree :)
One thing I am a little worried about is that URLFOR returns a url that has a timestamp in it /resource/1349463045000/name/path. If you don't include the timestamp will it always point to the latest uploaded version?
Thanks!
Scott
A quick test makes it look like it points to the latest version, so it should be a decent solution