You need to sign in to do that
Don't have an account?
using variables in Dynamic SOQL part II
Yesterday, I posted the following code because I couldn't get the unitFilter variable to return a value inside of the getStrategyQuery() method. I managed to get the unitFilter variable working. Now I am stuck on the on selectedUnit variable. It's giving me the same problem...for some reason it's returning null inside of the method. I don't understand why and at a loss at how to get it.
On vf page there is a picklist of selectOptions which are the units. When a user selects a particular unit the page should re-render. I can see in the viewState log that the selectedUnit variable is being populated with the selection made...so again, not sure why it's not being found in the method that uses it to create the query string getStrategyQuery()
thanks for any help.
public with sharing class narrativeWizard_Controller { public String accountID; public String swpnAccount { get; set; } public SchoolWorkPlanLog__c getLog { get; set; } public List<UniversalJoin__c> juncObs { get; set; } public List<cAIS> theWrappers { get; set; } public Map<ID,List<cAIS>> theWrapperMap { get; set; } public List<DeployedStrategy__c> theDSs { get; set; } public List<cGS> theGoalWrappers { get; set; } public Set<String> unitOptions = new Set<String>(); public String selectedUnit { get; set; } public Set<String> princyOptions = new Set<String>(); public String selectedPrincy { get; set; } public Set<String> catyOptions = new Set<String>(); public String selectedCaty { get; set; } public List<cCONS> theConWrappers { get; set; } public List<cCASES> theCaseWrappers { get; set; } public String unitFilter { get; set; } //sets up class extension of SchoolWorkPlanLog__c private final SchoolWorkPlanLog__c swpn; //CONSTRUCTOR public narrativeWizard_Controller(ApexPages.StandardController swpnController) { this.accountID = ApexPages.currentPage().getParameters().get('aID'); this.swpn = (SchoolWorkPlanLog__c)swpnController.getRecord(); this.setUpAccount(); this.makesStrategyWrappers(); this.makesGoalWrappers(); this.makesContactWrappers(); this.makesCaseWrappers(); this.getLog= new SchoolWorkPlanLog__c(); this.getUnits(); this.setUpUnitFilter(); this.getAllStrategies(); } public void setUpAccount() { Account acct = [select ID, Name from Account where ID = :accountID Limit 1]; this.swpnAccount = acct.Name; } public String setUpUnitFilter() { ID UP = Userinfo.getUserId(); User userX = [select ID, Name, Department__c, Unit__c from User where ID =:UP]; return userX.Unit__c; } //sets up the query string for the makesStrategyWrappers method below private String getStrategyQuery() { unitFilter = setUpUnitFilter(); String losFilters = ''; if(selectedUnit == 'All') { losFilters += ''; }else if((null != selectedUnit) && (selectedUnit != 'All')) { losFilters += ' AND Unit__c =:selectedUnit'; }else if (null != unitFilter) { losFilters += ' AND Unit__c =:unitFilter'; }else { losFilters += ''; } return 'select ID, Name, Status__c, Strategy__r.Name,Strategy__r.Category__r.Name, Strategy__r.Category__r.Principle__r.Name, EndDate__c, Unit__c, StartDate__c, (select ID, Name, Name__c, Status__c, DeployedStrategy__r.Strategy__r.Name, EndDate__c, LatestRating__c from DeployedActionItem__r Order By ItemNumber__c ASC) from DeployedStrategy__c where Account__c = :accountID And Status__c = \'Active\''+losFilters; } //attempt at Dynamic Query public void makesStrategyWrappers() { //variables theDSs = new List<DeployedStrategy__c>(); List<cAIS> cAIS1 = new List<cAIS>(); theWrappers = new List<cAIS>(); theWrapperMap = new Map<Id, List<cAIS>>(); String queryString = this.getStrategyQuery(); theDSs = Database.query(queryString); for(DeployedStrategy__c ds : theDSs) { for(DeployedActionItems__c actI : ds.DeployedActionItem__r) { cAIS1 = theWrapperMap.get(ds.Id); if(null == cAIS1) { cAIS1 = new List<cAIS>(); theWrappers.add(new cAIS(actI)); theWrapperMap.put(ds.Id, cAIS1); } cAIS1.add(new cAIS(actI)); } } } //pulls all Strategies to populate filter options public void getAllStrategies() { for(DeployedStrategy__c ds : [select ID, Name, Status__c, Strategy__r.Name,Strategy__r.Category__r.Name, Strategy__r.Category__r.Principle__r.Name, EndDate__c, Unit__c, StartDate__c, (select ID, Name, Name__c, Status__c, DeployedStrategy__r.Strategy__r.Name, EndDate__c, LatestRating__c from DeployedActionItem__r Order By ItemNumber__c ASC) from DeployedStrategy__c where Account__c = :accountID And Status__c = 'Active']) { unitOptions.add(ds.Unit__c); princyOptions.add(ds.Strategy__r.Category__r.Principle__r.Name); catyOptions.add(ds.Strategy__r.Category__r.Name); } } //makes Goal Wrappers public void makesGoalWrappers() { thegoalWrappers = new List<cGS>(); if(theGoalWrappers.size() <1) { for(Goal__c gs1 : [select ID, Unit__c, Account__c, Name, Status__c, StartDate__c, EndDate__c, Pillar__c, DemographicType__c from Goal__c where Account__c = :accountID and Status__c = 'Active']) { theGoalWrappers.add(new cGS(gs1)); } } }....more code but not relevant.
First of all I don't understand why are you not using any action in actionSupport but I assume your req do not need any action. I would suggest you to add a attribute immediate="true" in your action supoort ,
Just give it a try and let me know.
All Answers
Are you calling an AJAX function ( are you using actionFunction ) on change of picklist, please share that part of you VFP that you use to make call on change of picklist? I think your actionFunction is immediate true and you are not passing parameter also, but would be better if I see your VFP code once.
yes. I am using actionSupport on the picklist to reRender the table. I have added some stuff to try to debug, which are in bold below. I'm using the {Now()} statement to confirm that the section is actually rerendering...by seeing that the time stamp changes. The {!selectedUnit} statement shows me that the property is actually being populated by the selection being made. dt and dt2 are two more timestamps that declared inside of the getStrategyQuery() and makeStrategyWrappers() methods. These two show a time stamp when the page is opened...they have the same time as the first time stamp. However, when select a unit...only the first time stamp changes...dt and dt2 don't change, which tells me that the methods are not being called...but still not sure about what to do.
First of all I don't understand why are you not using any action in actionSupport but I assume your req do not need any action. I would suggest you to add a attribute immediate="true" in your action supoort ,
Just give it a try and let me know.
The page behaved slightly differently by additing immediate = true attribute.
The ultimate goal of getting the table to reRender did not happen. However, the debugging tags that I added behaved differently. All 3 timestamps worked the same as described above...which is that the first one always changes but the dt and dt2 do not change when the page is reRendered. The difference is that tag that is pulling the selectedUnit property into the page was not returning a value. Without the immeidate attribute it would show the value that was selected...with immediate attribute nothing is returned.
I got it. You were right. I needed to use the Action attribute to call the method.
Thanks