You need to sign in to do that
Don't have an account?
![DTCF DTCF](https://dfc-org-production.my.site.com/img/userprofile/default_profile_45_v2.png)
Add all field values from Object to Map dynamically
I need to get all field values from an Object and dynamically add them to a Map with the name of the field as the key. I can get the field names with a describe, and query all fields by appending them to a comma separated string and then using that string in my SOQL query, but I don't know how to iterate through all fields and add them to a map.
The reason why I need to do this is that I want to be able to get the values from the Object dynamically rather than having to explicitly reference a field name. They will all be strings, so I don't have to worry about that.
Instead of String value = CustomObject.Field_One__c;
I would like to do map.get('Field_One__c')
Something like that. I don't know how to iterate over all field names in the first place and construct the map. Thank you in advance!
This is already available to you. Every Custom Object is an SObject and SObject provides "get" and "put" methods that function like a HasMap. Look here for more information.