function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
theitdeptrockstheitdeptrocks 

Dynamic List Item Return Statement

public string getMyAnswer() { list<Administrative_Task__c> QuestionandYearAns = null; QuestionandYearAns = Database.query('select '+ currentQuestion + ' from Administrative_Task__c where plan__c = '+ '\''+SelectedPlanID+'\'' + ' AND year__c =' + '\''+YEQYearValue+'\'');

return QuestionandYearAns[0].Completed_By_Last__c; // return QuestionandYearAns[0].currentQuestion; }

 Hi all,

 

I'm looking for a way to acheive the above (in red).  From my query statement, you can see that a variable called currentQuestion is used to specify which Administrative_Task__c field to return, which is chosen by the user on the front end.  I would like to be able to return the field dynamically without having to explicity list which field to return (blue).

 

Any help would be greatly appreciated!

 

Thanks!

 

Best Answer chosen by Admin (Salesforce Developers) 
gm_sfdc_powerdegm_sfdc_powerde

You can use this -

 

return (String) QuestionandYearAns[0].get(currentQuestion);

 

 

 

All Answers

gm_sfdc_powerdegm_sfdc_powerde

You can use this -

 

return (String) QuestionandYearAns[0].get(currentQuestion);

 

 

 

This was selected as the best answer
theitdeptrockstheitdeptrocks
Thanks!  Worked like a charm.