You need to sign in to do that
Don't have an account?
Badar Ali 19
Search based on variable field name
Hi,
I would like to know that how can we search based on a custom field which we get as a parameter in a method.
For example if I create a custom field Mobilephone for the standard object Account, then how can I search this custom field Mobilephone?
String phone_number = '1'; String param = 'MobilePhone__c'; Account[] a = [select Name, Id, phone, :param from Account where param =: phone_number];
Both the search field and value to be searched have to be used from the variable.
If you know, please help me with this.
Thanks.
I think you need to use Developer Console => Edit=> Search In files and put the name whatever you want to search.
it will indicate you where all your search value is used in the class.
don't forget to mark it as best answer if it helps you.
Thank you
Refer snippet below:
// slash is to escape the single quote
String phone_number = '\'1\'';
String param = 'phone';
String query='select Id, Name,'+param+' from Account where '+param+'='+phone_number;
//use debug to check query first
System.debug('query=>'+query);
List<Account> accList=Database.query(query);
System.debug(''+accList);
Additionally we can connect on pradeepgore60@gmail.com
Mark this as best answer if this solves your problem
#DeepDivesIntoSalesforce
Pradeep Gore