How to disable/enable related list buttons based on triggers. - Answers - Salesforce Trailblazer Community
Trailblazer Community
Ask Search:
Ben MeyersBen Meyers 

How to disable/enable related list buttons based on triggers.

I am wondering if functionality exists somewhere in Salesforce to enable/disable related list buttons based on triggers.  My company is trying to transition all sales workflows into Salesforce.  To eliminate errors we want to limit some functionality until certain steps are taken.  Currently we have Assets attached to Opportunities.  Before a user can create an Asset we want at least one Product added to the Opportunity.  If zero Products are added to an Opportunity we want to disable the "New Asset" button located on the Asset related list.  When a product is added to an Opportunity we want to enable the "New Asset" button.  

I am a software programmer so any ideas (hard or easy) would be helpful.  
Best Answer chosen by Moderator (salesforce.com) 
Marko LamotMarko Lamot
Hello,

you would need to implement visualforce page with related list and put buttons there. In visualforce page you will be able to set "disabled" property to a button based on whether the product is entered or not.
However this requires quite some programming. Therefore you may also consider that user gets error on button press: "Can't add an asset. Please enter product first". If that is acceptable, than you can replace existing "add asset" button with your custom button, where you'll first check the number of products, and if OK, only then show NEW asset page.

kind regards, 
Marko Lamot, 
Agilcon, SF Implementation & Consulting, EU
 

All Answers

Eric KintzerEric Kintzer
Ben:

One solution:

This requires Visualforce replacements for the standard Opportunity View page (you override the View button with the VF page).

The VF page interacts with a controller that you write in APEX that sets Boolean properties such as 'assetCreateable' based on database state (in your case, presence of Opportunity Products).

You'll build custom related lists on your VF page where the New Asset button (a apex:commandButton) is conditionally rendered based on value of controller property assetCreateable.  The related list itself is built from a apex:pageblockTable componet, also drawing in from the Controller the current set of children Assets

This is a much bigger topic than this answer can do justice to but if you search for 'visualforce custom related lists' you'll find some examples to work through
Marko LamotMarko Lamot
Hello,

you would need to implement visualforce page with related list and put buttons there. In visualforce page you will be able to set "disabled" property to a button based on whether the product is entered or not.
However this requires quite some programming. Therefore you may also consider that user gets error on button press: "Can't add an asset. Please enter product first". If that is acceptable, than you can replace existing "add asset" button with your custom button, where you'll first check the number of products, and if OK, only then show NEW asset page.

kind regards, 
Marko Lamot, 
Agilcon, SF Implementation & Consulting, EU
 
This was selected as the best answer