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

Customized Account Search
I am trying to create a Visualforce Page that passes in a string to a SOQL query to create a list of Accounts that match the string, but I not able to get any results
Controller:
Visual Search Page:
List of Results Page:
Any help would be so appreciated. Thanks.
Controller:
public class AccountSearch_CC { public String acctName {get; set;} public List<AccountWrapper> accountList { get { if (accountList == null) { accountList = new List<AccountWrapper>(); for (Account acct : [SELECT Name, BillingAddress, Industry, Vertical_Assignment__c FROM Account WHERE NAME =: acctName ]){ accountList.add(new AccountWrapper(acct)); } } return accountList; } set; } public Map<ID, AccountWrapper> selectedAccounts { get { if (selectedAccounts ==null) { selectedAccounts = new Map<Id, AccountWrapper>(); } return selectedAccounts; } set; } public PageReference listAccounts(){ selectedAccounts.clear(); for(AccountWrapper acctWpr : accountList) { if(acctWpr.checked) { selectedAccounts.put(acctWpr.acct.Id, acctWpr); } } if (selectedAccounts.size()>0){ return Page.AcctSearch; } else { ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 'Please select at least one Account')); return null; } } public List<Account> available{ get { if (available == null) { available = new List<Account>([SELECT Name, BillingAddress, Industry, Vertical_Assignment__c FROM Account WHERE Id IN : selectedAccounts.keySet()]); } return available; } set; } public PageReference newSearch() { PageReference newPage = Page.SearchAccountPage; newPage.setRedirect(true); return NewPage; } public class AccountWrapper { public Account acct {get; set;} public Boolean checked {get; set;} public AccountWrapper(Account a){ acct = a; checked = false; } } }
Visual Search Page:
<apex:page controller="AccountSearch_CC" tabStyle="Account"> <apex:form > <apex:pageBlock title="Account Search"> <apex:pageMessages > </apex:pageMessages> <apex:pageBlockButtons > <apex:commandButton action="{!listAccounts}" value="See Available Accounts" /> </apex:pageBlockButtons> <apex:pageBlockTable var="a" value="{!accountList}"> <apex:column width="25px" headerValue="Select"> <apex:inputCheckbox value="{!a.checked}" /> </apex:column> <apex:column value="{!a.acct.Name}"/> </apex:pageBlockTable> </apex:pageBlock> </apex:form> </apex:page>
List of Results Page:
<apex:page controller="AccountSearch_CC"> <apex:form > <apex:pageBlock title="Search for Accounts"> <apex:pageMessages /> <apex:pageBlockButtons > <apex:commandButton action="{!newSearch}" value="New Search" /> <apex:inputText value="{!acctName}" id="SearchString" maxlength="25" size="30"/> </apex:pageBlockButtons> <apex:pageBlockTable var="avail" value="{!available}"> <apex:column value="{!avail.Name}"/> </apex:pageBlockTable> </apex:pageBlock> </apex:form> </apex:page>
Any help would be so appreciated. Thanks.
Below is the simple sample code which i used.Thought it could help you.
Hope this helps you!
Please accept my solution as Best Answer if my reply was helpful. It will make it available for other as the proper solution. If you felt I went above and beyond, you can give me kudos.
Thanks and Regards
Sandhya
All Answers
Below is the simple sample code which i used.Thought it could help you.
Hope this helps you!
Please accept my solution as Best Answer if my reply was helpful. It will make it available for other as the proper solution. If you felt I went above and beyond, you can give me kudos.
Thanks and Regards
Sandhya
Thank you so much. What I love about your solution is it is so simple compared to mine. I will post my results when finished. Thanks again.
Robert