I'm trying to pass a picklist value to a method if statement to change up the query based on what is selected form a picklist. When I try to use the if statement below I get a variable does not exist. I'm using public String SearchField {get;set;} to bring in the picklist values to the controller. Is there a way to use the SearchField Value from the picklist in the method below?
method:
@RemoteAction
global static List<InnerClassAccount> getAccounts(String toQuery) {
List<InnerClassAccount> ret = new List<InnerClassAccount>();
List<Schema.FieldSetMember> fields = Schema.SObjectType.Account.fieldSets.Search_Businesses.getFields();
List<Fields> fieldsInner = new List<Fields>();
String query = 'SELECT ';
String SearchField = 'd';
for(Schema.FieldSetMember f : fields) {
if(f.getFieldPath().contains('.')) {
String [] split = f.getFieldPath().split('\\.');
fieldsInner.add(new Fields(f.getFieldPath(),split[0] + ' '+f.label));
}else {
fieldsInner.add(new Fields(f.getFieldPath(),f.label));
}
if(f.getFieldPath()!= 'Id' && f.getFieldPath()!= 'Name'&& f.getFieldPath()!= 'ShippingAddress' && f.getFieldPath()!= 'BillingAddress'&& f.getFieldPath()!= 'OwnerID' ){
query += f.getFieldPath() + ', ';
}
}
if (SearchField = 'Name') {
String filter = '%' + toQuery + '%';
query += 'Id, Name,ShippingAddress,BillingAddress, OwnerID, TSGADX__MainParentId__c FROM Account WHERE Name LIKE :filter';
if (SearchField = 'Phone') {
String filter1 = '%' + toQuery + '%';
query += 'Id, Name,ShippingAddress,BillingAddress, OwnerID, TSGADX__MainParentId__c FROM Account WHERE Phone LIKE :filter1';
if (SearchField = 'Address') {
String filter2 = '%' + toQuery + '%';
query += 'Id, Name,ShippingAddress,BillingAddress, OwnerID, TSGADX__MainParentId__c FROM Account WHERE BillingAddress LIKE :filter2 or ShippingAddress like :filter2';
}}}