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
BaguiarBaguiar 

SelectList value to be on SOQL

Hi,

 

Trying to get the final part of this to work. I Have two Lists on thei VF page that control the values for the Criteria in the SOQL on the controller "TaskLeader". For the "Positions" list, I'm able to load the VF page fine and update the values and use the "Refresh" button to re-run the query. Now for the "rangedate" list, whatever value I select, it is still defaulting to 30 (days).

 

 

<apex:page controller="Taskleader" showHeader="false" >
<apex:form >
<apex:pageBlock id="pageBlock" Title="Activities logged">
<apex:pageMessages ></apex:pageMessages>
<apex:selectList id="Positions" value="{!positions}" size="1" title="Select Position">
<apex:selectoption itemLabel="President" itemValue="President"></apex:selectoption>
<apex:selectoption itemLabel="Co-President" itemValue="Co-President"></apex:selectoption>
</apex:selectList>
<apex:selectList id="rangedate" value="{!rangedate}" size="1" title="Last X Days">
<apex:selectoption itemLabel="30" itemValue="30"></apex:selectoption>
<apex:selectoption itemLabel="60" itemValue="60"></apex:selectoption>
<apex:selectoption itemLabel="90" itemValue="90"></apex:selectoption>
</apex:selectList>
<apex:commandButton action="{!Refreshtsk}" value="Run Report" />
<apex:pageBlockTable value="{!tsk}" var="tskl" rendered="{!NOT(ISNULL(tsk))}">
<apex:column headerValue="Name" ><apex:outputLink value="/{!tskl.who.id}" target="_parent">{!tskl.who.Name}

</apex:outputLink></apex:column>
<apex:column headerValue="Subject" ><apex:outputLink value="/{!tskl.id}" target="_parent">{!tskl.subject}

</apex:outputLink></apex:column>
<apex:column value="{!tskl.Activity_Type__c}"></apex:column>
<apex:column value="{!tskl.status}"></apex:column>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:form>

</apex:page>

 

public class Taskleader
{

    public PageReference Refreshtsk() {
        return null;
    }

 
  public String positions {get; set;}
  public String rangedate {
           get {
            if (rangedate == null) rangedate = '30' ;
            return rangedate;
        }
        set;
    }

  Date candDate=System.today();
  Date candDate1=candDate-Integer.valueOf(rangeDate);


  private List<task> tsk;
  public List<task> gettsk()

    {
    TAsk[] tsk = [select id, subject, who.name, status, Activity_type__C, activitydate, what.name, Account.BillingCity, Account.BillingState FROM Task WHERE WhoID IN ( SELECT Contact__c FROM Leadership_position_code__c WHERE Position__c = :positions and  (Thru_Date__c = null OR Thru_Date__c > :system.today()) and (Start_Date__C <= :system.today()) ) and OwnerID = :UserInfo.getUserId() and createddate >= :candDate1];
    return tsk;
    }
}

 on the  "public String rangedate"  I had t use the "IF" statement as the VF page is loaded through a link and the value for the "rangedate" can't be null when the page is loaded. The problem is that after the page is loaded, regardless of the value selected for the rangedate, it is still defaulting to 30.  Had a good help on other issues on this page yesterday and appreciate any inputs..

 

Thanks,

B

 

sravusravu

Ok in you method refreshTsk you are not performing any action. You will have to set the Apexpage parameters to the new selected rangedate.

 

you can do that as follows:

 

ApexPages.CurrentPage().getParameters().put('rangedate','new value');

BaguiarBaguiar

Thanks Sravu.

humm.. tried that and added the line to the Refreshtsk method.

 

public PageReference Refreshtsk() {
    ApexPages.CurrentPage().getParameters().put('rangedate','new value');
        return null;

 

 

Nothing happened. Same results. rangedate defaults to 30 days. Changed the value on te select list to 60, hit the button and still returning only 30 days. the query is OK as if  I maually change the range date on the SOQL, it returns the right records..

 

t

sravusravu

instead of returning null in the method add the parameter to the existing page so that when you click on the refresktsk button the page will have the rangedate parameter with the new value. If you set the parameter to the page then only you will get that parameter in the url.

BaguiarBaguiar

Sorry, not sure here. With the "return null;" I'm getting the values from the "positions" selectList. That is working fine when I Hit the "refresh" button with the method "Refreshtsk()".

 

Thanks a lot for the assistance!

sravusravu

What is happening right now is that when you select the rangeDate it is not actually passed to the controller. That is why it is always taking the default value that you have set. In the controller try using the following code:


String defaultValue = '30';


public String getrangedate(){

   return defaultValue;

}


public String setrangedate(String defaultValue){

   this.defaultValue = defaultValue;

}

 

 

instead of

 

public String rangedate {
           get {
            if (rangedate == null) rangedate = '30' ;
            return rangedate;
        }
        set;
    }

BaguiarBaguiar

Hi Sravu, Tried that but then I loose the reference to the "rangedate" as I get an error saying the variable does not exist on:

 

 Date candDate=System.today();
  Date candDate1=candDate-Integer.valueOf(rangedate);

 

I need that for the criteria on the query  ".. createddate >= :candDate1 "

 

I tried to change that (the "rangedate" value on the "date" line) to "defaultValue' as you've suggested with the String defaultvalue = '30', but then I get an error syaing i can;t return a velue or have a statement after a return statement at line:

 

this.defaultValue = defaultValue

 

 

thanks a million..

 

BaguiarBaguiar

Actually changed the code a little so i have now both strings exactly the same way. What I don;t understand now is that why on the "positions" string, when I call the "refreshtsk()" from a button on the VF page, I get the recortds updated according to the selection on the SelectList and when I do the same thing on the "rangedate", it does not update accorting to the selection. It seems to default to "null" all the time.

 

If it defaults to null all the time and it is based on the "  return null; " on the refreshtsk() Method, why does the "positions" works just fine, not defaulting to null after the page is loaded ?

 

 

public class Taskleader
{

    public PageReference Refreshtsk() {
 
        return null;
    }

  public String positions {get; set;}
  public String rangedate {get; set;}
           
    Date candDate=System.today();
    Date candDate1=candDate-(rangedate== null ? 30 : Integer.valueOf(rangeDate));

  private List<task> tsk;
  public List<task> gettsk()

    {
    TAsk[] tsk = [select id, subject, who.name, status, Activity_type__C, activitydate, what.name, Account.BillingCity, Account.BillingState FROM Task WHERE WhoID IN ( SELECT Contact__c FROM Leadership_position_code__c WHERE Position__c = :positions and  (Thru_Date__c = null OR Thru_Date__c > :system.today()) and (Start_Date__C <= :system.today()) ) and OwnerID = :UserInfo.getUserId() and createddate >= :candDate1];
    return tsk;
    }
}

 

 

 

Thanks,