0

I have created one Custom Button same name as "Submit For Approval" I have choose the behavior as "Execute JavaScript"

I have created one extension class public class AccountExtensionController {
public Id accountId {get;set;} public List accountList {get;set;} public Boolean hideSubmitForApprovalButton {get;set;}

private ApexPages.StandardController standardController;

public AccountExtensionController(ApexPages.StandardController standardController)
{
    this.standardController = standardController;
    showHideButton();
    system.debug('Check1');
} 
public Boolean showHideButton()
{
    accountId= ApexPages.currentPage().getParameters().get('id');
    hideSubmitForApprovalButton =false;
    system.debug('Check2'+hideSubmitForApprovalButton );
    accountList =[select id, Ownership from account where id =: accountId];
    if(accountList.size()>0)
        {
            if(accountList[0].Ownership == 'Private' || accountList[0].Ownership  == 'Subsidiary')
            {
                hideSubmitForApprovalButton=true;
                system.debug('Check3'+hideSubmitForApprovalButton );
            }
        }
         system.debug('Check4'+hideSubmitForApprovalButton );
        return hideSubmitForApprovalButton;
}

} VF Class

if ('{!Account.Ownership} == 'Private'' ) hideButton("Submit_For_Approval_Test"); function hideButton(Submit_For_Approval_Test) { try { var buttons = parent.document.getElementsByName(btnName); for (var i=0; i

1
  • function hideButton(Submit_For_Approval_Test) { try { var buttons = parent.document.getElementsByName(btnName); 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); } } </script> </apex:page>
    – Neha
    Sep 21, 2017 at 10:38

1 Answer 1

0

you can go with the below code too. In this you can show and hide all possible buttons using CSS and JAVASCRIPT .Passing ownership as a variable in the function

CODE. CSS CODE .btnDisabled {display:none;} .btnEnabled {display:block;}

JAVASCRIPT CODE function toggleButtons(Ownership) { var myButtonClasses = document.getElementById("btnName").classList; if(Ownership=='Private' ||Ownership=='Subsidiary' ){ if (myButtonClasses.contains("btnDisabled ")) { myButtonClasses.remove("btnEnabled"); } else { myButtonClasses.add("btnDisabled "); } } }

You must log in to answer this question.

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