+ Start a Discussion
Sweta GSweta G 

How to create Custom visual force page to load case data. For custom Case detail page. There should be 2 sections.  Section 1 should keep case data for selected case.  Section 2 should display cases which is assigned to log in user.

Best Answer chosen by Sweta G
SHAHNA MULLASHAHNA MULLA

Hi,

Try this code, it may help.

Visualforce Page :
<apex:page controller="CustomCasePage_Controller" >
     <apex:form >
         
         <br/> <h2>CHOOSE A CSAE FROM LIST</h2>
         <apex:pageBlock>
         	<apex:selectList value="{!val}"  multiselect="false" size="1">
         		<apex:actionSupport event="onchange" action="{!changeList}" reRender="myblck"/>
         			<apex:selectOptions value="{!items}">
         			</apex:selectOptions>
         	</apex:selectList>
         </apex:pageBlock><br/><br/>
         
         <apex:pageBlock id="myblck" title="Section 1 : Case data for selected Case" >
             <apex:pageBlockTable value="{!case_final_list}" var="i">
            	<apex:column value="{!i.CaseNumber}"/>
            	<apex:column value="{!i.Status}"/> 
            	<apex:column value="{!i.Origin}"/>
             </apex:pageBlockTable>
         </apex:pageBlock><br/><br/>
         
         <apex:pageBlock title="Section 2 : Cases which is assigned to login user">
       	 	<apex:pageBlockTable value="{!CaseList2}" var="i">
            	<apex:column value="{!i.CaseNumber}"/>
            	<apex:column value="{!i.Status}"/> 
            	<apex:column value="{!i.Origin}"/>
            </apex:pageBlockTable>
         </apex:pageBlock><br/><br/>
         
    </apex:form>
</apex:page>

Controller :
public class CustomCasePage_Controller {        
    
    public List<Case> CaseList1{get;set;}
    public List<Case> CaseList2{get;set;}
    public String Val{get;set;}
    public list<case> case_final_list{get;set;}
    public List<SelectOption> opt {get;set;}
    
    public CustomCasePage_Controller(){
       getlist2();       
    }
    
    public List<Case> getlist2(){
        CaseList2 = [SELECT  CaseNumber,Status,Origin from Case WHERE OwnerId=:UserInfo.getUserID()];
        return CaseList2;
    }
    
    public List<SelectOption> getItems() {
         opt = new List<SelectOption>();
         CaseList1 = [select id,CaseNumber from Case];
         opt.add(new SelectOption('none','--select--'));
         for(Case a:CaseList1)
            opt.add(new SelectOption(string.valueof(a.id),a.CaseNumber));
         return opt;
        }
    
     public void changeList(){ 
        id caseid=id.valueof(Val);
        case_final_list =[select id,CaseNumber,Status,Origin from case where id=: caseid];           
       }
}

Can you please Let me know if it helps or not!!!

If it helps don't forget to mark this as a best answer!!!

Thanks....

All Answers

SHAHNA MULLASHAHNA MULLA

Hi,

Try this code, it may help.

Visualforce Page :
<apex:page controller="CustomCasePage_Controller" >
     <apex:form >
         
         <br/> <h2>CHOOSE A CSAE FROM LIST</h2>
         <apex:pageBlock>
         	<apex:selectList value="{!val}"  multiselect="false" size="1">
         		<apex:actionSupport event="onchange" action="{!changeList}" reRender="myblck"/>
         			<apex:selectOptions value="{!items}">
         			</apex:selectOptions>
         	</apex:selectList>
         </apex:pageBlock><br/><br/>
         
         <apex:pageBlock id="myblck" title="Section 1 : Case data for selected Case" >
             <apex:pageBlockTable value="{!case_final_list}" var="i">
            	<apex:column value="{!i.CaseNumber}"/>
            	<apex:column value="{!i.Status}"/> 
            	<apex:column value="{!i.Origin}"/>
             </apex:pageBlockTable>
         </apex:pageBlock><br/><br/>
         
         <apex:pageBlock title="Section 2 : Cases which is assigned to login user">
       	 	<apex:pageBlockTable value="{!CaseList2}" var="i">
            	<apex:column value="{!i.CaseNumber}"/>
            	<apex:column value="{!i.Status}"/> 
            	<apex:column value="{!i.Origin}"/>
            </apex:pageBlockTable>
         </apex:pageBlock><br/><br/>
         
    </apex:form>
</apex:page>

Controller :
public class CustomCasePage_Controller {        
    
    public List<Case> CaseList1{get;set;}
    public List<Case> CaseList2{get;set;}
    public String Val{get;set;}
    public list<case> case_final_list{get;set;}
    public List<SelectOption> opt {get;set;}
    
    public CustomCasePage_Controller(){
       getlist2();       
    }
    
    public List<Case> getlist2(){
        CaseList2 = [SELECT  CaseNumber,Status,Origin from Case WHERE OwnerId=:UserInfo.getUserID()];
        return CaseList2;
    }
    
    public List<SelectOption> getItems() {
         opt = new List<SelectOption>();
         CaseList1 = [select id,CaseNumber from Case];
         opt.add(new SelectOption('none','--select--'));
         for(Case a:CaseList1)
            opt.add(new SelectOption(string.valueof(a.id),a.CaseNumber));
         return opt;
        }
    
     public void changeList(){ 
        id caseid=id.valueof(Val);
        case_final_list =[select id,CaseNumber,Status,Origin from case where id=: caseid];           
       }
}

Can you please Let me know if it helps or not!!!

If it helps don't forget to mark this as a best answer!!!

Thanks....
This was selected as the best answer
Sweta GSweta G
Hi Shahna ,

Thank you for your help :) 
But Section 1 is not workig :(

Thanks,
Sweta
SHAHNA MULLASHAHNA MULLA

Hi Sweta,

Section1 is working for me. Can you clear  your  Error with Section1?

Thanks....
Sweta GSweta G
Yes I am trying but it is not showing list of cases in 1st section..
SHAHNA MULLASHAHNA MULLA

Hi,

I got the following result.... Let me know whether you got the same or not....
And please inform me, if you are looking for a different requirement......

User-added image

User-added image

User-added image

Thank you......
Sweta GSweta G
Hi Shahna,
I got following output ,I am not getting that what i missed

:User-added image

Thanks,
Sweta
SHAHNA MULLASHAHNA MULLA

Hi,

I think 'getItems()' is not working properly.....
Did you made any change in the code. If so, can you share your code ......
Other ways check the following query in your query editor,
select id,CaseNumber from Case​
Sweta GSweta G
Error  is:- Unexpcted token 'select'.
SHAHNA MULLASHAHNA MULLA

Hi,

Put your SOQL statements in square brackets  [SELECT ...] and try.
Eg : [select id,CaseNumber from Case​]
Sweta GSweta G
Error  is:- Unexpcted token 'select'.