2

I have created one vf page in which all pages and apex classes in my org are shown. I have 2 problems 1. I want to get owner name for each apex class and apex pages. 2. I want one checkbox which will act as a select all values in my coloumn

vf page

<apex:page controller="vfpagectrl" sidebar="false" >
    <script type="text/javascript">
        function checkall(cb,filter)
        {
            var inputItem=document.getElementsByTagName("inputcheckbox");       
            for(var v=0;v<inputItem.length;v++)
            {
                if(inputItem[i].id.indexOf(filter)!=-1)
                {
                   inputItem[i].checked= cb.checked;
                }        
            }    
        }
    </script>

    <apex:form >
        <apex:pageBlock >
            <apex:pageblockSection title="Apex Classes and Pages" >
                <apex:pageblockTable value="{!aclass}" var="a">
                    <apex:column headerValue="selectall" >       
                        <apex:inputCheckbox value="{!se}" id="check" selected="true"/>
                    </apex:column>
                    <apex:column value="{!a.Name}"/>            
                    <apex:column value="{!a.CreatedDate }"/>                   
                </apex:pageblockTable>
                <apex:pageBlockTable value="{!apage}" var="w">
                    <apex:column headerValue="selectall" > 
                        <apex:inputCheckbox value="{!se}" id="check"  selected="true"/>
                    </apex:column>
                    <apex:column value="{!w.Name}"/>
                    <apex:column value="{!w.CreatedDate}"/>
                </apex:pageBlockTable>
            </apex:pageblockSection>        
        </apex:pageBlock>
    </apex:form>
</apex:page>

Controller

public class vfpagectrl {
    public List<apexclass> aclass{get;set;}
    public List<apexpage>  apage{get;set;}
    public String se{get;set;}
    public vfpagectrl()
    {
        aclass=new List<apexclass>();        
        aclass=[select Name,Status,CreatedDate from apexclass where Status='Active'];       
        apage=new List<apexpage>();        
        apage=[select Name,CreatedDate,ControllerKey from apexpage];    
    }
    public List<User> getuid()
    {
        return null;    
    }
}   
1

Solution for Problem 1:

There is no field called owner for Apex Classes, Apex Triggers and Visualforce pages.

You can use CreatedBy.Name and LastModifiedBy.Name to show who created it first and who modified it last.

Solution for Problem 2:

We used JQuery to select all the checkboxes once the top check box is checked. We need to uncheck the top check box if any of the bottom checkboxes is unchecked.

function test(){
    j$ = jQuery.noConflict();                        
    // add multiple select / deselect functionality
    j$(function() {                                    
        j$("input.selectAll").click(function () {                                
            j$("input.checkBox").prop('checked', this.checked);
        });

        // if all checkbox are selected, check the selectall checkbox
        // and viceversa
        j$("input.checkBox").click(function(){     
            if(j$("input.checkBox").length == j$("input.checkBox:checked").length)
                j$("input.selectAll").prop("checked", true);
            else 
                j$("input.selectAll").prop("checked", false);                         
        });

        j$("input.selectAllExisting").click(function () {                                
            j$("input.checkBoxExisting").prop('checked', this.checked);
        });

        // if all checkbox are selected, check the selectall checkbox
        // and viceversa
        j$("input.checkBoxExisting").click(function(){     
            if(j$("input.checkBoxExisting").length == j$("input.checkBoxExisting:checked").length)
                j$("input.selectAllExisting").prop("checked", true);
            else 
                j$("input.selectAllExisting").prop("checked", false);                         
        });
    });
}

<apex:column >
    <apex:facet name="header">
        <apex:inputCheckbox value="{!boolSelectExisting}" styleClass="selectAllExisting" onchange="test()"/>
    </apex:facet>
    <apex:inputCheckbox value="{!bpr.Selected}" styleClass="checkBoxExisting" onchange="test()"/>
</apex:column>
  • @Vingeshwaran G: Do you made any changes in apex controller?? – Shantanu Mahajan Jul 10 '15 at 12:34
  • You should modify this query by adding CreatedBy.Name aclass=[select Name,Status,CreatedDate,CreatedBy.Name from apexclass where Status='Active']; and add <apex:column value="{!aclass.CreatedBy.Name}"/> to visualforce page. – Vigneshwaran G Jul 10 '15 at 13:11
  • I am talking about the jqury.SOQL is working fine – Shantanu Mahajan Jul 11 '15 at 16:22
  • The jquery i showed is an solution which we applied for specific condition. You can modify it according to your need. The controller doesn't need any changes i believe. – Vigneshwaran G Jul 11 '15 at 17:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.