You need to sign in to do that
Don't have an account?
Carter85
Open pdf static resource with button press in new window
I'm trying to open a pdf I've saved as a static resource in a new window off a button press. The idea is to allow different representatives while dealing with customers to be able to pull up the specific form for a policy in a separate window if the need arises to quote directly from it. At the moment my button code is something like the below just to test, but if anyone has a better idea how, either how to call it or where to save the forms to in the first place. to do it I'm open to suggestion, because the the moment the below is producing the error:
A problem with the OnClick JavaScript for this button or link was encountered: missing : after property id
window.open('/viewStaticResource.apexp?id='+{MG_MAG_Claim__c.FID__c})", '_blank');
I have done this with a simple VF page, something like:
Create a custom button that launches this page in a new window, add the button to your layout, et voila!
I've tried putting the JS into a custom JS button, but the $Resource global variable isn't available in JS buttons, only in VF pages. Go figure.
If this helps, please mark it as a solution, and give kudos (click on the star) if you think I deserve them. Thanks!
-Glyn Anderson
Certified Salesforce Developer | Certified Salesforce Administrator
I think your suggestion is what I'm looking for, however I'm running into a little bit of trouble accounting for all the potential variations. It would be simple if every one of the instances would only need one specific resource, but as we have different forms for various products I'm trying to make sure the right one is assigned to each new entry on the claim object. I have this at the moment for the new VF popup:
where {!MG_MAG_Claim__c.FID__c} equals something like: {!$Resource.F069}
However, at the moment when I press the new button it does open the new popup, but it is simply blank, so I'm not sure if it's a syntax error or if I just can't manipulate a resource reference like that, so if you had any additional thoughts I'd welcome them.
It won't work to have a merge field evaluate as another merge field. The substitution is only done once.
Instead, try creating a different script block for each possible static resource PDF file. Put each of those into it's own <apex:outputPanel> with the "rendered" attribute = to something like "{!IF(MG_MAG_Claim__c.FID__c==XXX)}", where XXX is whatever the field needs to equal in order to display that PDF file. This way, only the desired script will be rendered and executed.
-Glyn
Are there any settings I might have to allow for within salesforce aside from making the resource public to get the pdf to display properly in the window? Because for some reason I'm still getting a blank page, while the pdf is auto downloaded to my desktop rather than opened to view, even when I go back and try your first suggestion with something like:
I think your latest suggested method will work, but for this one wrinkle.
Never mind, that was just caused by a brower issue with firefox I'll need to make allowances for somehow.
Ok, so I've been trying to separate the outputpanels as you suggested with the render attribute, however, I think I'm missing something in my controller because when I try to grab the FID from the page it doesn't seem to be getting it with what I have so far, or for some reason it doesn't like rendering the static resource when there's a render attribute on the panel because the {!show} variable definitely contains the F069 value in my tests and if I take out the rendered test and just leave it
it renders no problem.
Thoughts?
VF at the moment:
Controller:
Add quotes aroung the F069 in the rendered attribute and fix the syntax (you don't need the IF):
Let me know if that does it.
-Glyn
Unfortunately no, just opens a blank page.
It is not feasible by static resource, but you can do it with the document object, upload the pdf in a document and then query the URL of pdf.
I suggest you visit this link:
https://developer.salesforce.com/docs/atlas.en-us.sfFieldRef.meta/sfFieldRef/salesforce_field_reference_Document.htm
I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.
Thanks and Regards,
Deepali Kulshrestha