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
hramanihramani 

Adding all the fields (api names) into a list

I have a code where there is a map containing and its fields.
I want to extract all the fields from those 2 objects (Contact and Application__c) and store them in a list. I have just declared a Map and added values to it. 
How do I extract all the fields of those two fields and store them in a List. Please help


Map<String,List<String>> objectMap = new Map<String,List<String>>();
List<String> newList = new List<String>{'Contact.Name','Contact.Id'};
List<String> newList1 = new List<String>{'Application__c.Name','Application__c.Id'};

objectMap.put('Contact',newList);
objectMap.put('Application__c',newList1);
 
Lokesh KumarLokesh Kumar
Use this code snippet to get the fields of the object 
Schema.DescribeSObjectResult r = Account.sObjectType.getDescribe();
List<String>apiNames =  new list<String>();
for(string apiName : r.fields.getMap().keySet()){
   apiNames.add(apiName);
}
System.debug(apiNames);