Converting List to map
I have a query that
List OList = [select id,name,fld3,fld4,fld5 from Opportunity]
i need to add field name like 'id,name,fld3,fld4 etc,.. as map keys and results of the fields as map values
List<Opportunity> OList = [select id,name from Opportunity]
like
[
id = Olist.id,
name = Olist.name
.....
]
Is it possible to make like that?
Best Answer
Have I understood your question correctly?
You are looking for data structure like this?
You can use a
Map<String,List<Object>>
data structure to hold all the field values. Then convert the SObject into a Map itself to loop over its fields easily. Here's a code sample that yields the above: