You need to sign in to do that
Don't have an account?

how to get Records in Apex Controller of three different objects
Hi
I am getting No Records in the page showing No Units to display
can any one help me in this
I have created a Button and calling the below VF :
I have the following code for VF and Controller
++++++++++++++++++++Page++++++++++++++++++++
<apex:page StandardController="Project__c" extensions="Add_Units_Site_Project">
<apex:form >
<apex:outputPanel >
<apex:pageBlock id="pageblock">
<apex:pageBlockButtons >
<apex:commandButton Value="Process Selected Units" onclick="return validateSelection1();"/>
<apex:commandButton Value="Go Back" action="{!cancel}" />
</apex:pageBlockButtons>
<apex:pageBlockSection title="Unit Events" id="unitevents" columns="1" collapsible="true" >
<apex:pageBlockTable value="{!uniteventlist}" id="TableData" var="u">
<!--rendered="{!NOT(ISNULL(uniteventlist))}" -->
<apex:column headerValue="Select All" >
<apex:facet name="header">
<apex:inputCheckbox id="chkSelectAll" title="Select All" value="{!chkFlag}">
<apex:actionSupport event="onclick" action="{!chkAllBox}" />
</apex:inputCheckbox>
</apex:facet>
<apex:selectCheckboxes value="{!Selected}" id="ids" >
<apex:selectOption itemvalue="{!u.ID}" />
</apex:selectCheckBoxes>
</apex:column>
<apex:column headerValue="Unit Event Id"><apex:outputField value="{!u.Otg_ID__c}"/></apex:column>
<apex:column headerValue="Outage Type"> <apex:outputField value="{!u.Otg_Type__c}"/></apex:column>
<apex:column headerValue="Outage Quarter"> <apex:outputField value="{!u.Otg_Qtr__c}"/></apex:column>
</apex:pageBlockTable>
<apex:outputLabel value="No Units are available for this Site Outage Project Account" rendered="{!NoOfUnits == 0}"> </apex:outputLabel>
</apex:pageblocksection>
<apex:pageBlockButtons location="bottom" rendered="{!NOT(ISNULL(uniteventlist))}">
<table width="100%" rendered="{!NOT(ISNULL(uniteventlist))}"><tr></tr><tr><td align="left">
<apex:commandLink value="<< First" action="{!getFirst}" reRender="pageblock" rendered="{!hasFirst}" />
<apex:outputText value="<< First" rendered="{!NOT(hasFirst)}" />
<apex:commandLink value="< Previous" action="{!getPrev}" reRender="pageblock" rendered="{!hasPrev}" />
<apex:outputText value="< Previous" rendered="{!NOT(hasPrev)}" />
<apex:commandLink value="Next >" action="{!getNext}" reRender="pageblock" rendered="{!hasNext}" />
<apex:outputText value="Next >" rendered="{!NOT(hasNext)}" />
<apex:commandLink value="Last >>" action="{!getLast}" reRender="pageblock" rendered="{!hasLast}" />
<apex:outputText value="Last >>" rendered="{!NOT(hasLast)}" />
</td><td align="right">
<apex:outputText >Records {!StartRec}-{!EndRec} of {!NoOfUnits} </apex:outputText>
</td></tr></table>
</apex:pageBlockButtons>
</apex:pageBlock>
</apex:outputpanel>
</apex:form>
<script type="text/javascript">
var selectedCount = 0;
function validateSelection1()
{
var inputElem = document.getElementsByTagName("input");
for(var i=0; i<inputElem.length; i++)
{
if(inputElem[i].id.indexOf("ids")!=-1 || inputElem[i].id.indexOf("chkSelectAll")!=-1)
{
if(inputElem[i].checked==true)
{
selectedCount=1;
}
}
}
if(selectedCount == 0)
{
alert('Select a Unit to add to the Site Outage Project ');
return false;
}
return true;
}
</script>
</apex:page>
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
And the Controller as follows :
++++++++++++++++++Contoller +++++++++++++++++++++++++++++++++++
Public Class Add_Units_Site_Project{
Public Project__c proj {get;set;}
//Public Installed__c IB {get;set;}
//Public Outage_c units {get;set;}
Public List <Installed> IBlist = new List <Installed>();
Public List <Outage__c> Units = new List <Outage__c>();
Private String projid;
Public String Accid;
Public Integer NoOfUnits{get;set;}
Private Integer NextCount=0;
Public Integer NoOfRows=20;
Public Boolean hasNext{get;set;}
Public Boolean hasPrev{get;set;}
Public Boolean hasFirst{get;set;}
Public Boolean hasLast{get;set;}
Public Integer StartRec{get;set;}
Public Integer EndRec{get;set;}
Public void getNext()
{
if(NextCount+NoOfRows <= NoOfUnits)
NextCount+=NoOfRows;
else
NextCount = NoOfUnits - NoOfRows;
}
Public void getPrev()
{
if(NextCount-NoOfRows >=0)
NextCount-=NoOfRows;
else
NextCount=0;
}
Public void getFirst()
{
NextCount=0;
}
Public void getLast()
{
NextCount=NoOfUnits - NoOfRows;
}
public Add_Units_Site_Project(ApexPages.StandardController controller) {
//Fetching the Current Record ID
projid =ApexPages.currentPage().getParameters().get('id');
proj =[select id,name,Account__c,Account__r.id,Account_Name__c,RecordTypeid from Project__c where id =: projid];
//Fetching Current Record Account ID
Accid = [select id,name from Account where id =:proj.Account__c].id;
IBlist = [Select id,name,Account__r.id from Installed__c where Account__c = : Accid];
Units = [Select id,name,S_N__c,Site_Outage_project__c from Outage__c where S_N__c in : IBList ];
}
public List<Outage__c> uniteventlist= new List<Outage__c>();
public List<Outage__c> getuniteventlist() {
if(uniteventlist.size()==0)
return null;
For(Integer i=0; i<NoOfRows && NextCount+i < NoOfUnits; i++)
{
Units.add(uniteventlist[NextCount+i]);
}
if(NextCount <= 0)
{
hasFirst=False;
hasPrev=False;
}
else
{
hasFirst=True;
hasPrev=True;
}
if(NextCount >= (NoOfUnits - NoOfRows))
{
hasLast=False;
hasNext=False;
}
else
{
hasLast=True;
hasNext=True;
}
StartRec=(NoOfUnits == 0)?0:NextCount+1;
if(StartRec+NoOfRows > NoOfUnits)
EndRec=NoOfUnits;
else
EndRec=StartRec+NoOfRows -1;
if(Units.size()>0)
return Units ;
else { return null; }
}
public boolean chkFlag{get; set;}
public void chkAllBox()
{
if(chkFlag == true)
{
for(outage__c unitevnts : uniteventlist )
{
Selected.add(unitevnts.id);
}
}
else
Selected.clear();
}
public id[] selected = new id[]{};
public id[] getSelected()
{
return Selected;
}
public void setSelected(id[] selected)
{
if(chkFlag == false)
this.Selected.addAll(selected);
}
}
Please confirm if your issue is resolved?
All Answers
Problem is with your below code
public List<Outage__c> getuniteventlist() {
if(uniteventlist.size()==0)
return null;
it will always return null
Please confirm if your issue is resolved?