• kpit
  • NEWBIE
  • 0 Points
  • Member since 2007

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 9
    Replies
Hi, I need to build dynamic queries by passing variables values to the statement from the choice an user has done from a selection list.
 
For example: I got a list with these values (representing field names from a SObject): 'Field1__c', 'Field2__c', 'Field3__c', ..., 'FieldX__c'. So I got the selected value and I want to build a query according to the user choice like this:
 
Code:
String strSelectedField = Myobject.RequestedField__c; // This passes the selected FieldName from the combobox.
Map<String, Account> FoundValuesMap = new Map<String, Account>();
for(Account QueryResult : [Select strSelectedField from Account]){
  FoundValuesMap.put(QueryResult.strSelectedField, QueryResult);
}

 Obviously, if I try this code an error comes up saying that the FieldName "strSelectedField" doesn't exist on Account object. I tried to put before the variable name the caracter ":" but another error appears saying there is an unexpected token (:). I can not define those fieldnames because the list of fields could change without notice.
 
How could I pass the variable to query to make SOQL understand the value as a fieldname?
 
Thanks for any given help.
 
Regards,
 
WILMER
  • November 20, 2007
  • Like
  • 0
Is it possible to leverage lead conversion process in Apex? I did not find any relevant information on this in the documentation.

This is how conversion is done via API, can I do this with Apex Code?

sforce.LeadConvert leadConvert = new sforce.LeadConvert();
...
...
lcr = binding.convertLead(new sforce.LeadConvert[] {leadConvert});
  • August 15, 2007
  • Like
  • 0
Given that queries in Apex code are performed differently, is it possible to make the fields requested from an object variable?  As the documentation implies, a "bind" expression cannot be used.  If this is not possible by some other approach, it would be a valuable enhancement/improvement.
 
Also, is there a way to investigate the fields on an object (akin to a DescribeSObject) when a trigger fires?  Ideally something like a .js 'for ... in ... ' loop:
for(thisField in thisAccount)
{
    //do something w/ thisField.name
}
 
Thanks!