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

DropDown query list of Users then add to query
Hi all,
I'm sure this is possible but I currently can't find the answer so looking for some help or direction.
I want to create a drop down in a VF page that is a list of active users with their associated ID so when a user is selected from the dropdown the ID is added to the below query replacing the userinfo.getuserid.
Public static integer getWeb_Corporate() { integer Web_Corporate = [SELECT count() FROM Lead where OwnerId =:UserInfo.getUserId() AND LeadSource='Web-Corporate' AND IsConverted = False AND List_Assignment__c != 'Corporate' LIMIT 1000]; return Web_Corporate ; }
Any help would be appreciated.
Kev
I see that you are binding <p>{!Web_Corporate}</p> to the page which is supposed to invoke getWeb_Corporate(). But the getter can not be static
So your property should be ....
All Answers
Create a property in controller like below
public string userId{get;set;}
assign this to the value attribute of your <apex:selectlist value="{!userId}" onchange="<call an action function>"
create an actoin function that will do a rerender of the panel that you want to be refreshed. The function that is to be called upon triggering action Function should have no code.
And in your getter property.... do the dynamic query instead of direct query by changing the user id parameter. like below:
Public static integer getWeb_Corporate()
{
integer Web_Corporate = Database.query('SELECT count() FROM Lead where OwnerId =: userId AND LeadSource='Web- Corporate' AND IsConverted = False AND List_Assignment__c != 'Corporate' LIMIT 1000');
return Web_Corporate ;
}
Thanks, however, I can't seem to get it to work.
I have the below as a test:
Apex Class - get an error:
Error: Compile Error: expecting a right parentheses, found 'Web' at line 7 column 107
This seems to be referring to the query.
And a test VF Page - item valuing being the User ID
your dynamic query should be like below.... with single quotes escaped...
Thanks, however, I now get the error:
Error: Compile Error: Illegal assignment from LIST<SObject> to Integer at line 6 column 5
Ok... I anticipated this... try this...
Thanks that fixed the issue, however, now when I run the page I get the below:
caused by: System.QueryException: Variable does not exist: userId
Class.AAATESTDROPDOWN.getWeb_Corporate: line 8, column 1
The page code I'm using is the below:
I'm guessing this is because the query isn't get sent a value when the page loads.
I see that you are binding <p>{!Web_Corporate}</p> to the page which is supposed to invoke getWeb_Corporate(). But the getter can not be static
So your property should be ....
Thanks that fixes the first part now I just need to work out, how to pass the drop down value to the query.