2

If the user is one of a few profiles, a button should appear on a standard page layout. However, this isn't working. It's rendering to everyone. In the debug logs, the VF isn't getting called when I load the Opp. How do i get this to work?

 <apex:page standardController="Opportunity" extensions="OpportunityController" action="{!redirect}" rendered="{!render}" />

Apex:

public with sharing class OpportunityController {

    String oppId;

    public OpportunityController(ApexPages.StandardController controller) {
        this.oppId = ApexPages.currentPage().getParameters().get('id');
                system.debug(UserInfo.getProfileid());
        getRender();
    }

    public PageReference redirect(){
        PageReference p;
        String s = '/setup/ui/recordtypeselect.jsp?id=' + this.oppId +'&retURL=%2F'+ this.oppId;
        p = new PageReference(s);
        return p;   
    }



    public boolean getRender(){
   if (UserInfo.getProfileid() == '123' || UserInfo.getprofileid() == '234' ) {
       return true;
   }
         return false;

    }
}
1
  • A small improvement you can make to your controller code is to use the StandardController to get the Id, this.oppId = controller.getId(); Sep 7, 2013 at 10:10

1 Answer 1

2

Unfortunately (and having never noticed the rendered attribute on apex:page myself), i have doubled checked this and the assumption that this will control Custom Button visibility is sadly not correct. The Visualforce page is only invoked when the user presses the button and not before.

So what you could do is handle it via a message, using apex:pageMessages and ApexPages.addMessage in your 'redirect' method, returning null if your getRender() method return false. The page will display with your message, and you can then provide a cancel button via apex:commandButton action="{!cancel}", since your using a StandardController.

The question of making Custom Buttons on native layouts has come up before, as well as this very popular Idea here (please add your upvote). There is some discussion of using Record Types and Layouts, as well as some JavaScript hacks here, Disable custom button on detail page on some condition..?

1

You must log in to answer this question.

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