You need to sign in to do that
Don't have an account?
Siddharth
Apex function is being binded multiple times on click of command button
Hello,
I have written an apex class which has function called getCampaigns(). This functions executes parameterized queries and returns a wrapper list.
On my Visualforce page i have a search panel which filter the campaigns based on Dates and other criterias. When i click on the command button to execute this function in the SystemLog i could see it executing 2-3 times and also it doesnot maintain the new dates in text boxes after postback.
Below is a small snippet from the code:
private Integer FitlerStatus;
private Integer IsPostBack = 1;
WrapperCalender[] wrapExtn;
private Integer IsPostBack = 1;
WrapperCalender[] wrapExtn;
public PageReference GetAllData()
{
MonthSDate = '';
MonthEDate = '';
MonthStartDate = null;
MonthEndDate = null;
this.FitlerStatus = 1;
IsPostBack = 4;
wrapExtn = getCampaigns();
return null;
}
{
MonthSDate = '';
MonthEDate = '';
MonthStartDate = null;
MonthEndDate = null;
this.FitlerStatus = 1;
IsPostBack = 4;
wrapExtn = getCampaigns();
return null;
}
public WrapperCalender[] getCampaigns()
{
if (IsPostBack == 2 && FitlerStatus == 0)
{
cmpList = [Select c.StartDate,c.EndDate,c.Id, (Select id, Name, Budget_Status__c From CMOExtensions__r) from Campaign c
where IsActive = true and startdate >=: MonthStartDate and startdate <=: MonthEndDate
and startdate != null order by c.StartDate asc];
}
else
{
if (IsPostBack == 3)
{
cmpList = [Select c.StartDate,c.EndDate,c.Id, (Select id, Name, Budget_Status__c From CMOExtensions__r) from Campaign c
where IsActive = true and startdate >=: MonthStartDate and enddate <=: MonthEndDate
and startdate != null order by c.StartDate asc];
}
if (IsPostBack == 4)
{
cmpList = [Select c.StartDate,c.EndDate,c.Id, (Select id, Name, Budget_Status__c From CMOExtensions__r) from Campaign c
where IsActive = true and startdate != null order by c.StartDate asc];
}
}
wrapExtn = new WrapperCalender[cmpList.size()];
if(cmpList !=null && cmpList.size()>0)
{
//
}
}
{
if (IsPostBack == 2 && FitlerStatus == 0)
{
cmpList = [Select c.StartDate,c.EndDate,c.Id, (Select id, Name, Budget_Status__c From CMOExtensions__r) from Campaign c
where IsActive = true and startdate >=: MonthStartDate and startdate <=: MonthEndDate
and startdate != null order by c.StartDate asc];
}
else
{
if (IsPostBack == 3)
{
cmpList = [Select c.StartDate,c.EndDate,c.Id, (Select id, Name, Budget_Status__c From CMOExtensions__r) from Campaign c
where IsActive = true and startdate >=: MonthStartDate and enddate <=: MonthEndDate
and startdate != null order by c.StartDate asc];
}
if (IsPostBack == 4)
{
cmpList = [Select c.StartDate,c.EndDate,c.Id, (Select id, Name, Budget_Status__c From CMOExtensions__r) from Campaign c
where IsActive = true and startdate != null order by c.StartDate asc];
}
}
wrapExtn = new WrapperCalender[cmpList.size()];
if(cmpList !=null && cmpList.size()>0)
{
//
}
}
So now when i access GetAllData() on command button click then all the 3 scenarios gets executed. Can someone prove help or suggestion, that would be appreciated.
thanks in advance
Siddharth
{! Campaigns}
on your page?
if so, then each place this appears is calling getCampaigns()
I checked my code and it is being called just once. There is just one page block section which calls this function.
<apex:pageBlock title="">
<apex:pageBlockTable value="{!Campaigns}" var="cmp">
<apex:column value="{!cmp.StartDate}" width="6%">
<apex:facet name="header">Start Date</apex:facet>
</apex:column>
<apex:column value="{!cmp.EndDate}" width="7%">
<apex:facet name="header">End Date</apex:facet>
</apex:column>
</apex:pageBlockTable>
</apex:pageBlock>
so, your button calls getalldata, which calls getCampaigns,
then the page is redrawn and the page calls getCampaigns to resolve the expression {!campaigns}
so it should be firing twice, as far as i can tell from your descriptions