+ Start a Discussion
HayaHaya 

Accessing data in VF

I asked about this before.

I don't know how to access the data that I need.

 

I have a VF page:

<apex:page standardController="Case" extensions="CaseExtension" >
<apex:pageBlock title="Viewed Cases" rendered="{! IF (case.Status=='', true, false)}">
<apex:form >
<apex:dataTable value="{!case}" var="s" columns="5" cellspacing="15" >
<apex:column value="{! s.CaseNumber}" headerValue="Case Number" />
<apex:column value="{! s.Contact}" headerValue="Contact Name" />
<apex:column value="{! s.Reason}" headerValue="Reason" />
<apex:column value="{! s.CreatedDate}" headerValue="Created Date" />
<apex:column value="{! s.Owner}" headerValue="Owner" />
</apex:dataTable>
</apex:form>

</apex:pageBlock>
</apex:page>

 

I don't know how to set up the Controller Extension. I read about get and put, I tried various codes, but i am not having any success in accessing the data.

 

I would very much appreciate help with this matter.

 

 

Best Answer chosen by Admin (Salesforce Developers) 
SRajesh8SRajesh8

HI,

 

Try this

 

public class CaseExtension {
public list<Case> case1{get;set;}
    public CaseExtension(ApexPages.StandardController controller) {
      
    }
    public list<Case> getcases()
    {
     case1=[Select CaseNumber,Contactid,reason,CreatedDate,Ownerid from case limit 10];   
     return case1;
    }

}

 

VF PAge:

 

<apex:page standardController="Case" extensions="CaseExtension" >
<apex:pageBlock title="Viewed Cases" rendered="{! IF (case.Status=='', true, false)}">
<apex:form >
<apex:dataTable value="{!cases}" var="s" columns="5" cellspacing="15" >
<apex:column value="{! s.CaseNumber}" headerValue="Case Number" />
<apex:column value="{! s.Contactid}" headerValue="Contact Name" />
<apex:column value="{! s.Reason}" headerValue="Reason" />
<apex:column value="{! s.CreatedDate}" headerValue="Created Date" />
<apex:column value="{! s.Ownerid}" headerValue="Owner" />
</apex:dataTable>
</apex:form>

</apex:pageBlock>
</apex:page>

 

Regards,

Rajesh.

 

All Answers

Amritesh SinghAmritesh Singh

Hi Haya,

 

I think this is your solution.

See below VF Page n Associaled Controller :

 

VF Page:

 

<apex:page standardController="Case" extensions="CaseExtension" >
<apex:pageBlock title="Viewed Cases" rendered="{! IF (case.Status=='', true, false)}">
<apex:form >
<apex:dataTable value="{!case1}" var="s" columns="5" cellspacing="15" >
<apex:column value="{! s.CaseNumber}" headerValue="Case Number" />
<apex:column value="{! s.Contactid}" headerValue="Contact Name" />
<apex:column value="{! s.Reason}" headerValue="Reason" />
<apex:column value="{! s.CreatedDate}" headerValue="Created Date" />
<apex:column value="{! s.Ownerid}" headerValue="Owner" />
</apex:dataTable>
</apex:form>

</apex:pageBlock>
</apex:page>

 

Controller :

 

public with sharing class CaseExtension {
    
    public list<Case> case1{get;set;}
    public CaseExtension(ApexPages.StandardController controller) {
     case1=[select id,CaseNumber,Contactid,Reason,CreatedDate,Ownerid from Case];
    }

}

 

 


Regards,

Amritesh

SRajesh8SRajesh8

HI,

 

Try this

 

public class CaseExtension {
public list<Case> case1{get;set;}
    public CaseExtension(ApexPages.StandardController controller) {
      
    }
    public list<Case> getcases()
    {
     case1=[Select CaseNumber,Contactid,reason,CreatedDate,Ownerid from case limit 10];   
     return case1;
    }

}

 

VF PAge:

 

<apex:page standardController="Case" extensions="CaseExtension" >
<apex:pageBlock title="Viewed Cases" rendered="{! IF (case.Status=='', true, false)}">
<apex:form >
<apex:dataTable value="{!cases}" var="s" columns="5" cellspacing="15" >
<apex:column value="{! s.CaseNumber}" headerValue="Case Number" />
<apex:column value="{! s.Contactid}" headerValue="Contact Name" />
<apex:column value="{! s.Reason}" headerValue="Reason" />
<apex:column value="{! s.CreatedDate}" headerValue="Created Date" />
<apex:column value="{! s.Ownerid}" headerValue="Owner" />
</apex:dataTable>
</apex:form>

</apex:pageBlock>
</apex:page>

 

Regards,

Rajesh.

 

This was selected as the best answer
HayaHaya

Thank you for your answers.

 

I tried both solutions. I am not getting any syntax errors but I am also not getting any date.

 

I get the column headings on the page but no data.

 

Do I need to define the database somehow?

 

Is my IF statement wrong?  

 

So far I haven't been able to get even one record.

Amritesh SinghAmritesh Singh

Do you have any records in Case???

I think you Case object doesn't contains any record thats y table is blank.

!st create some case then check again.

 

 

Regards,

HayaHaya

There are records when I view them with the usual Cases tab.

It's when I try to access them with the visual page that I don't get the data.

 

I created 2 new cases, they are showing up in the Cases tab, but not in my visual page.

Amritesh SinghAmritesh Singh

I think u r missing somthng,bcs this code is fine and working for me..!!!

 

 

now i have to see your page n controller,which i cant..!!!

 

 

HayaHaya

Can you please give me ideas of where to look. I am searching everywhere to see what I am missing.

 

This is such a simple query and I can't make it work.

 

Any help would be greatly appreciated.

Amritesh SinghAmritesh Singh

I dont know i have to see your page .

 

Try rerender as making true only..

HayaHaya

Eureka! It works!

 

I am not sure what combination of things that I tested made it happen.

 

Thank you so much for your help.

 

Haya

HayaHaya

You have been very helpful.

 

I have another question.

 

I want to add Account Name to the page. It is not in the Case database , it is  lookup field residing in the Account database.

 

How do I add it to my code? Do i need to define another dataTable?

 

This is what I have so far:

<apex:page standardController="Case" extensions="CaseExtension" >
<apex:pageBlock title="Viewed Cases" rendered="{! IF (case.Status=='', true, false)}">
<apex:form >
<apex:dataTable value="{!cases}" var="s" columns="7" cellspacing="15" > Priority
<apex:column value="{! s.Priority}" headerValue="Priority" />
<apex:column value="{! s.CaseNumber}" headerValue="Case Number" />
<apex:column value="{! s.Contactid}" headerValue="Contact Name" />
<apex:column value="{! s.CreatedDate}" headerValue="Date/Time Opened" />
<apex:column value="{! s.Ownerid}" headerValue="Case Owner Alias" />
</apex:dataTable>
</apex:form>

</apex:pageBlock>
</apex:page>

 

and

 

public class CaseExtension {
public list<Case> case1{get;set;}
    public CaseExtension(ApexPages.StandardController controller) {
     
    }
    public list<Case> getcases()
    {
     case1=[Select Priority,CaseNumber,Subject,Contactid,CreatedDate,Ownerid from case];  
     return case1;
    }

}

 

Amritesh SinghAmritesh Singh

Add Accountid in query n in column value also.

In cases Account  field resides as a lookup.

 

Let me know what Account Name you want to add.???

HayaHaya

Thank you again :)