You need to sign in to do that
Don't have an account?
EagerToLearn
list controller with free form input field
I am trying to write a list controller that will get a list of users showing two fields. The username and a text field as input on the visualforce page. When I click the "GO" button I want to call a method where I will use the list of users with the value in the text field to do some further work. Can someone help me with a block code for this and VF page. I think I need a wrapper class for the text field but I an't see to make sense from other examples as I don't see any were the text field is not a bind to any field on the user object.
Thanks for any help you can provide to get me started.
Thanks for any help you can provide to get me started.
As my understanding your requirement Please try this,
VF page
<apex:page controller="myController">
<apex:form>
<apex:pageBlock title="Users" mode="edit">
<apex:pageBlockButtons>
<apex:commandButton action="{!go}" value="Botton Go"/>
</apex:pageBlockButtons>
<apex:pageBlockSection title="User Details" columns="2">
<!-- if you are using any other custom object with user lookup, please replace {!userDetails} by ' {!getUserDetailsCustom}' -->
<apex:repeat value="{!UserDetails}" var="u">
<apex:outputField label="User Name" value="{!u.userName}"/>
<apex:inputField value="{!u.MyTextField__c}"/>
</apex:repeat>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
Controller class
public class myController {
// if you are using standard user object
public LIST<user> getUserDetails()
{
LIST<user> objUserList = [select username,MyTextField__c from user];
return objUserList;
}
// if you are using any custom object which has user lookup user object
public LIST<YourCostomObjectName__c> getUserDetailsCustom()
{
LIST<YourCostomObjectName__c> objUserList = [select user__r.name ,MyTextField__c from YourCostomObjectName__c];
return objUserList;
}
public void go(){
}
}
Regards
I need to create the test class next and usually struggle a bit on that put I will get it - just not as fast as I would like. Any further anhancedment suggestions or pointers were you see wholes in it I would appeciate the help/collaboration.
Visualforce:
Controller:
https://developer.salesforce.com/forums#!/feedtype=SINGLE_QUESTION_DETAIL&dc=Developer_Forums&criteria=OPENQUESTIONS&id=9060G0000005TmKQAU
but realized that it is kind of associated to the same work! I am getting an error List index out of bound: 0 from my test class. The page and code is working as expected but I can't get the test class issue resolved! Appreciate any support possible.