You need to sign in to do that
Don't have an account?
Dowithforce
Create dynamic listbox and SOQL query with its item
Hello All,
I need to fetch all fields of contact object and form a list box like as follows
- First Name
- Last Name
- Phone
by choosing a item from listbox need to form SOQL query with choosen field name for e.g. If I choose
Email field then my query will be
data = [Select Phone,Name,email,Title from contact where Email = NULL ] ;
return data;
I need to add "Email" field as dynamic value. Here I am getting value of listbox item in controller method, but I am not able to concate string in SOQL.
Can anyone help me? for following task
1. Create listbox with fetch fields from Contact object?
2. Create a dynamic field name value in SOQL?
Thanks
Dowithforce
Not sure why you do not have a response yet, it is straight forward. Here is how we have addressed this:
First, dynamic SOQL is easy:
String query = 'select ' + fieldList + ' from pat_Patient__c where id = \'' + id + '\'';
returnVal = (pat_Patient__c)Database.query(query);
(of course protect the string from sql injection)
Second, building the dynamic Dropdown list:
I hope this helps you, or anyone else who is trying to do something similar.
Steve