Getting All object fields dynamically without adding each and everything salesforce

Apex Snippet :
-----------------

Schema.DescribeSObjectResult[] descResult = Schema.describeSObjects(new String[]{'Lead'});      
Map<String, Schema.SObjectField> fsMap = descResult[0].fields.getMap();
List<String> fieldNames = new List<String>(fsMap.keySet());
String queryString;
for(String f:fieldNames){
    queryString = 'SELECT '+String.join(fieldNames,',')+' FROM Lead limit 1';
}
System.debug(queryString);
SObject obj = Database.query(queryString);
System.debug(obj);


No comments:

Featured

What is Cryptography in salesforce and what are all the algorithms provided by them ?

A). It is a security protocal between two systems. Lets say we are integration two systems without any encrytion mechanism then hackers wil...

Popular