0

I have a custom button on a custom object page from which I generate a VisualForce PDF document (Content Source = URL). There are conditions, however, where the PDF should not be generated based on the value of a field in the object.

I would like to build an IF condition on the button to open the PDF page if the value of the field is correct, but if not, to stay on the current page and display a message.

Salesforce discourages use of Javascript for buttons so I'm trying to find a different way, so if anyone can help I'd appreciate it. I've found articles but none showing how to do the 'else' condition I need.

{!if(ISPICKVAL (myObj__c.FieldA__c,"TypeA"),
     URLFOR("/apex/myPDF?myId="&myObj__c.Id),
     ....stay on page and display message.....}

I'd like to dispay a message on the current page to the effect of 'Sorry, you cannot generate a PDF for this item'.

The 'true' part of the IF works fine.

1 Answer 1

1
<apex:page standardController="MyObj__c" action="{!IF(ISPICKVAL (MyObj__c.FieldA__c,'TypeA'),
                            URLFOR(...),
                            NULL)}"/>
    <apex:pageMessage severity="warning" summary="Sorry, you can not ..."/>
</apex:page>

You can use the page action attribute and return NULL to stay on the page. The custom button references the VF page so you don't have to use any JS

2
  • The page my button is on is not a VF page. Are you meaning I should add this action to the PDF page that I'm opening from the button?
    – Irene
    Commented Sep 10, 2019 at 18:49
  • @Irene - yes; the button on the object page should be associated to a VF page that in effect, is a redirecting page - it redirects to either a PDF page or to a simple page with an error message
    – cropredy
    Commented Sep 10, 2019 at 19:02

You must log in to answer this question.

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