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
bhaskar reddy kbhaskar reddy k 

regarding case object

Hi all,
             This is bhaskar,new to salesforce coding.my question is i want to display all cases with checkbox,and a user him self to assign cases to  check the check box what he choose. can any body help me on this .
   Thanks in advance.


regards,
bhaskar

 
Best Answer chosen by bhaskar reddy k
Amit Chaudhary 8Amit Chaudhary 8
Please try below code
<apex:page Controller="SearchTask">
  
    <script type="text/javascript">
        function selectAllCheckboxes(obj,receivedInputID){
            var inputCheckBox = document.getElementsByTagName("input");
            for(var i=0; i<inputCheckBox.length; i++){
                if(inputCheckBox[i].id.indexOf(receivedInputID)!=-1){
                    inputCheckBox[i].checked = obj.checked;
                }
            }
        }
    </script>
    <apex:form >
        <apex:pageBlock id="PB1">
            <apex:pageBlockButtons >
                <apex:commandButton value="Add to Grid" action="{!processSelected}" rerender="table2,PB2"/>
            </apex:pageBlockButtons>

            <apex:pageblockSection title="All Case" collapsible="false" columns="1">
                <apex:pageBlockTable value="{!listCaseWrapper }" var="caseWrap" id="table" title="All Case">
                    <apex:column >
                        <apex:facet name="header">
                            <apex:inputCheckbox onclick="selectAllCheckboxes(this,'inputId')"/>
                        </apex:facet>
                        <apex:inputCheckbox value="{!caseWrap.selected}" id="inputId"/>
                    </apex:column>
                    <apex:column value="{!caseWrap.caseObj.Subject }" />
                    <apex:column value="{!caseWrap.caseObj.CaseNumber}" />
                </apex:pageBlockTable>
            </apex:pageblockSection>
        </apex:pageBlock>
        
        <apex:pageBlock id="PB2" >
            <apex:pageBlockButtons >
                <apex:commandButton value="Assign To me" action="{!AssignToMe}" rerender="PB1,PB2"/>
            </apex:pageBlockButtons>

                <apex:pageBlockTable value="{!selectedCase}" var="c" id="table2" title="Selected Accounts">
                    <apex:column value="{!c.Subject}" headerValue="Subject"/>
                    <apex:column value="{!c.CaseNumber }" headerValue="case number"/>
                </apex:pageBlockTable>
        </apex:pageBlock>

        
    </apex:form>
  
</apex:page>
public with sharing class SearchTask 
{
    public List<CaseWrapper> listCaseWrapper {get; set;}
    public List<Case > selectedCase {get;set;}
    
    public Searchtask()
    {
         listCaseWrapper = new List<CaseWrapper>();
        selectedCase= new List<Case>();
         searchRecord();
    }

    public void searchRecord()
    {
        listCaseWrapper.clear();
         selectedCase.clear();
            for(Case a: [select Id, ownerId,Subject,CaseNumber from Case limit 10]) 
            {
                listCaseWrapper.add(new CaseWrapper(a));
            }
    }

    public void processSelected() 
    {
        selectedCase= new List<Case>();
        selectedCase.clear();
        for(CaseWrapper wrapCaseObj : listCaseWrapper ) 
        {
            if(wrapCaseObj.selected == true) 
            {
                selectedCase.add(wrapCaseObj.caseObj);
            }
        }
    }

    public void AssignToMe() 
    {
        for(Case c: selectedCase)
        {
            c.ownerId=userinfo.getuserid();
        }
        update selectedCase ;
        searchRecord();
    }
    

    // This is our wrapper/container class. 
    public class CaseWrapper 
    {
        public Case caseObj{get; set;}
        public Boolean selected {get; set;}
        public CaseWrapper (Case c) 
        {
            caseObj= c;
            selected = false;
        }
    }
        
}

Let us know if this will help you

Thanks
Amit Chaudhary