I have an object with a picklist including two values "status" (Valid,Invalid).. I'm using search in my VF page dependent on the selected status from this picklist, so the SOQL should return the values where the status is equal "selected value".
While I'm searching for a solution I found this example, put should I use this complex way ! I tried to get the value as following but i got error.
VF Page Code:
<apex:pageBlock title="Account Search">
<apex:pageBlockSection>
<apex:inputField id="status" value="{!account.Status__c}"/>
</apex:pageBlockSection>
<apex:pageBlockButtons>
<apex:commandButton value="Search" action="{!getAccounts}"/>
</apex:pageBlockButtons>
</apex:pageBlock>
AccController Code:
public Account Account{set;get;}
public list<Account> Accounts{set;get;}
public AccController(){
Account= new Account();
}
public PageReference getAccounts(){
Accounts = Database.query('SELECT Name
from Account
WHERE Status__c = account.Status__c');
return null;
}
The Error : System.QueryException: Variable does not exist: account.Status__c
And If I put account.Status__c outside the singe comma like this WHERE Status__c = ' + account.Status__c
And Choose a value, for Example Valid, I got this Error
System.QueryException: unexpected token: 'Valid'