I need to get the commandButton to work when I press the plus sign on the row. I need the commandButton to be insivible. I think I might need some javaScript for this.

Here is my visualForce page

<apex:page sidebar="false" showHeader="false" controller="myEmployeeController3">
    <apex:includescript value="//code.jquery.com/jquery-1.11.1.min.js" / >
        <apex:includescript value="//cdn.datatables.net/1.10.4/js/jquery.dataTables.min.js" />
        <apex:stylesheet value="//cdn.datatables.net/1.10.4/css/jquery.dataTables.css" />

            p { font-weight: bold; }
            p {font-size: 15px;}
            h1,h2 {display:block;
            text-align: center;
            margin: 5px;
            margin-top: 10px;}
            h1 {font-size: 20px;}
            h2 {font-size: 16px;}
            #inputSection {text-align: center;
            margin-bottom: 10px;}

        function switchMenu(obj,obj1,obj2) 
            var el = document.getElementById(obj);                                       
            if ( el.style.display != 'none' ) {
                el.style.display = 'none';
            else {
                el.style.display = '';
            var e2 = document.getElementById(obj1);                                       
            if ( e2.style.display != 'none' ) {
                e2.style.display = 'none';
            else {
                e2.style.display = '';
            var e3 = document.getElementById(obj2);                                       
            if ( e2.style.display != 'none' ) {
                e3.style.display = 'none';
            else {
                e3.style.display = '';

        <apex:form >
            <h1>Permissions Inspector</h1>
            <h2>Enter Object API Name</h2>

            <div id="inputSection">
                <apex:inputText value="{!SObjectName}"/>
                <apex:commandButton action="{!actionSupMethod}" reRender="test2" value="Submit"/>
            <apex:actionfunction action="{!submitLead}" name="myFunction" reRender="PBS1">
                <apex:param name="recordId" value="" assignTo="{!recordId}"/>
            <apex:pageBlock >
                <apex:pageBlockTable id="test2" value="{!objectout}" var="cus" >
                    <apex:column >
                        <apex:facet name="header">                                        
                            THE RESULTS ARE                                                                             
                        <apex:outputpanel id="plusimage">
                            <apex:image url="{!$Resource.Plus_Image}" onclick="switchMenu
                                                                               ('{!$Component.inlinetablesec}','{!$Component.minusimage}','{!$Component.plusimage}')" title="Expand"/> 
                        <apex:outputpanel id="minusimage" style="display:none;">
                            <apex:image url="{!$Resource.Minus_Image}"
                                        onclick="switchMenu('{!$Component.inlinetablesec}','{!$Component.plusimage}','{!$Component.minusimage}')" title="Collapse"/>

                        <apex:outputpanel id="inlinetablesec" style="display:none;">
                            <apex:variable value="{!0}" var="rowNum"/>
                            <apex:repeat var="count" value="{!cus.Parent.Profile.Name}">
                                <apex:variable var="rowNum" value="{!rowNum+1}"/>
                                <!--<apex:commandButton value="Submit" onclick="myFunction('{!cus.ParentId}'); return false;" reRender="PBS1"/>-->
                            <apex:outputText rendered="{!rowNum=0}">  Element Set Null </apex:outputText>

                            <apex:pageblocktable value="{!dataMap}" var="tm" rendered="{!rowNum>0}" id="PBS1">

                                <apex:column headerValue="Field names">


                    <apex:column headerValue="Object" value="{!cus.SObjectType}"/>
                    <apex:column headerValue="Read" value="{!cus.PermissionsRead}"/>
                    <apex:column headerValue="Parent ID" value="{!cus.ParentId}"/> 
                    <apex:column headerValue="Edit" value="{!cus.PermissionsEdit}"/>p
                    <apex:column headerValue="Delete" value="{!cus.PermissionsDelete}"/>
                    <apex:column headerValue="ViewAll" value="{!cus.PermissionsViewAllRecords}"/> 
                    <apex:column headerValue="ModifyAll" value="{!cus.PermissionsModifyAllRecords}"/>



Here is my Controller

public with sharing class myEmployeeController3 {
    public String SObjectName{get;set;}
    public List<ObjectPermissions> objectout{get;set;}
    public List<FieldPermissions> fieldPerms{get;set;}
    public String recordId{get; set;}

     //public ID recor = ID.valueOf(recordId);

   // public Map<ObjectPermissions,List<FieldPermissions>> dataMap{get;set;}
    public Map<Id,ObjectPermissions> objMap{get;set;}
    public Map<Id,List<FieldPermissions>> dataMap{get;set;}

    public void submitLead() {
        System.debug('recordID ' + recordId);

        fieldPerms = [SELECT Field, ParentId
                     FROM FieldPermissions
                     WHERE ParentId=:recordId AND SObjectType =:SObjectName 
                     ORDER BY Field DESC];

        dataMap = new Map<ID,List<FieldPermissions>>();

        if(fieldPerms != null)
            System.debug('fieldPerms ' + fieldPerms);

            for(FieldPermissions fp :fieldPerms)
                    //needs to be number - is coming as text
                    dataMap.put(recordId,new List<FieldPermissions>());


        System.debug('dataMap ' + dataMap);
    public myEmployeeController3(){
        recordId= '';

    Public void actionSupMethod(){
        objectout =  [SELECT ParentId, Parent.Profile.Name, SObjectType, PermissionsRead, PermissionsCreate,PermissionsEdit,PermissionsDelete,
                      FROM ObjectPermissions 
                      WHERE SObjectType = :SObjectName AND (PermissionsRead = true OR PermissionsCreate = true 
                                                            OR PermissionsEdit = true OR PermissionsDelete = true 
                                                            OR PermissionsViewAllRecords = true OR PermissionsModifyAllRecords = true)
                      ORDER BY Parent.IsOwnedByProfile ASC];

         objMap = new Map<Id,ObjectPermissions>();
        if(objectout != null)
            for(ObjectPermissions op :objectout)
        System.debug('objMap values ' + objMap);


2 Answers 2


I see you're already familiar with action functions. So, since you wanted to hide the commandButton in the first place, I don't see any reason to keep it. So we could remove the commandButton:

<apex:commandButton action="{!actionSupMethod}" reRender="test2" value="Submit"/>

and use action function instead:

<apex:actionfunction action="{!actionSupMethod}" name="actionSupAF" reRender="test2"/>

Your plus sign element already calls a js function. So, to keep it we will create a new function that will call it first, and then our new Action Function:

function plusClick(obj,obj1,obj2) {

And finally change your plus image to call the new function:

<apex:image url="{!$Resource.Plus_Image}" onclick="plusClick('{!$Component.inlinetablesec}','{!$Component.minusimage}','{!$Component.plusimage}')" title="Expand"/>

Hide the command button inside a div and display it when the plus sign is clicked through a javascript.

<div id="buttonDiv" style="display:none;">
   <apex:commandButton action="{!whatever}" value="Click Me"/>
//javascript function can be like this
function showButton()
  document.getElementById("buttonDiv").style.display = 'block';

Hope this helps.

You must log in to answer this question.

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