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
@GM@GM 

Hide/Show custom button on standard page layout

There is custom button created (it redirects to VF on click of it) & placed on standard opportunity page layout.
 There is inline VF page present on same standard opportunity page layout.
 
Is it possible to control the appearance of this custom button (Show/Hide) based on the some fields value of opportunity records via JS or any approach without creating multiple page layouts or overriding std opportunity page layout with Vf page?
 
I looked into some of blogs but those solution will work only for the buttons present inside inline VF page or on overriding std page layouts
Ex : http://blogatsalesforce.blogspot.in/2015/04/enable-disable-buttons-on-standard.html
 
 
Alba RivasAlba Rivas
Hi,

You can hide standard buttons with Javascript, just inspect the page html, look for the button class or id of the button you want to hide, and write some javascript code to hide the button. You can write that JS as part of the inline VF page that you are including. This works. HOWEVER, bear in mind that salesforce may change its styles at any moment and your code will be broken then.

My advice is that, if it is possible, try to use standard things, as record types, to have different layouts with different buttons, as it is a much more elegant and strong solution.

Regards.
@GM@GM
HI Alba Azcona,

Thanks for the reply, The JS which we include in the inline VF page to hide the button wont work since the button wont appear always before inline VF page.

We cant go with WF with record type solution since we have many page layouts for diffrent profile. I'm looking for the solution to control the button from inline VF page via JS or something as you already mentioned and JS didn't worked :-(

Regards,
GM
Alba RivasAlba Rivas
Hi GM,

Your inline VF page is included in the standard layout, right? And that standard layout always contains the buttons. 

What if you try to embed the standard layout in your visualforce page using apex:detail? I think that should work.

Regards.

 
@GM@GM
Hi Alba Azcona,

Thank you for the reply.

If i override the 'View' button using VF page (apex:detail) then we will loose the inline editing and SFDC doc says that we can include 'inlineEdit = true' in the apex:detail attribute and it didn't worked. 

Regards,
GM.

 
Alba RivasAlba Rivas
That is wierd, I have some pages that use apex:detail and inlineEdit=true and it works for me. Do you want to copy your code here?

Regards.
@GM@GM
I found that the inlineEdit works fine if i didn't add JS code but it wont work on adding the JS code.

I added JS to hide/Show the custom button. Is there any problem in JS?

Page code: This page in used in overridding VIEW button of opportunity object
<apex:page id="editOppty" standardController="Opportunity" tabStyle="Opportunity" sidebar="true" showHeader="true">
    <apex:Detail inlineEdit="true" subject="{!Opportunity.ID}" relatedList="true" />


<script type="text/javascript">
    window.onload=function()      
    {      
        if ('{!Opportunity.MSA__c}' == 'Yes') hideButton("job_setup");
        if ('{!Opportunity.RFP_Required__c}' == 'true') hideButton("job_setup");  
    };
    // The code below is executed as soon as the page loads. Based on the value of the Opportunity field
   
    //if ('{!Opportunity.MSA__c}' == 'Yes') hideButton("job_setup");
    //if ('{!Opportunity.RFP_Required__c}' == 'true') hideButton("job_setup");


function hideButton(btnName) {
  try{
    var buttons = parent.document.getElementsByName(btnName);
    //alert("Hi buttons "+buttons);
    for (var i=0; i < buttons.length; i++) {
      buttons[i].className="btnDisabled ";
      buttons[i].disabled=true;
      buttons[i].type='hidden';
    }
  } catch(e) {
    // var ee = e.message || 0; alert('Error: \n\n'+e+'\n'+ee);
  }
}

function renameButton(btnName, newTitle) {
  try{
    var buttons = parent.document.getElementsByName(btnName);
    for (var i=0; i < buttons.length; i++) {
      buttons[i].value=newTitle;
    }
  } catch(e) {
    // var ee = e.message || 0; alert('Error: \n\n'+e+'\n'+ee);
  }
}
</script>


</apex:page>

Thank you.

Regards,
GM