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
jucuzoglujucuzoglu 

How do I return a SOQL query into a MAP

I would like to store the results of a SOQL query to a Map. My hope is that once the FieldName and Value is mapped that I could create a function where I pass a field name and the method can return the value from the map (along with some other processing that is not important for this example)

 

Assume that only a single row is returned.

 

[Select field1, field2, field3 from someObject Where Id=:someID]

 

 

spraetzspraetz

If you're trying to make it such that you can dynamically access fields on an Sobject with field names stored as strings, you can simply do that like this.

 

Account a = [SELECT name, field1, field2, field3 FROM Account WHERE id = :someId];

field_1_value = a.get("field1");

field_2_value = a.get("field2");

 

 

If this isn't what you meant, please let me know.

LeWizLeWiz

What if you wanted to automate this?

 

i.e. be able to select ALL fields from ANY object, and then generate a key/value pair that you could send via HTTPRequest?