function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
kevin.chileskevin.chiles 

Cannot render PDF from custom button unless record is in approved status

Hello!

 

I have a custom button that creates a pdf and emails it to a client from a custom object.  I now want to have the button only work when the record has a status of approved.  I have a status field Status__c, with multiple values, Approved being the one I want to have the fire off of.  I am not sure how to accomplish this.  The button is referencing a visual force page, and I am not sure if this condition needs to be set on the VF page or in the button (on click java script).  Any suggestions? 

Best Answer chosen by Admin (Salesforce Developers) 
PrabhaPrabha

Hi

 

There are two ways, I think of, you can achieve this.

 

1. Create record types on your custom object, and create two page layouts.

              Pagelayout1 : doesn't include your custom button and it is of record type1.

              Pagelayout2 : it has the custom button and it is  of record type2.

    now the magic in this solution is, in your final approval action section of approval process, have a field update which updates the record type field to "record type2"

 

2. Invoke a different vf page on the button click, this vf page <apex:page> will have an attribute "action" which checks for the condition if the status is approved or not and redirects the user to your vf page accordingly.

 

HTH

Prabhan

All Answers

PrabhaPrabha

Hi

 

There are two ways, I think of, you can achieve this.

 

1. Create record types on your custom object, and create two page layouts.

              Pagelayout1 : doesn't include your custom button and it is of record type1.

              Pagelayout2 : it has the custom button and it is  of record type2.

    now the magic in this solution is, in your final approval action section of approval process, have a field update which updates the record type field to "record type2"

 

2. Invoke a different vf page on the button click, this vf page <apex:page> will have an attribute "action" which checks for the condition if the status is approved or not and redirects the user to your vf page accordingly.

 

HTH

Prabhan

This was selected as the best answer
kevin.chileskevin.chiles

Thank you very much for your feedback.  I believe the second approach is the way to go.  I will Give it a shot and let you know how this plays out!