Example SOQL to query for all fields using Dyanamic Query in Apex
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// without an ID, simply specify the object to then derive the sobject type | |
DescribeSObjectResult describeResult = Account.getSObjectType().getDescribe(); | |
List<String> fieldNames = new List<String>( describeResult.fields.getMap().keySet() ); | |
String query = | |
' SELECT ' + | |
String.join( fieldNames, ',' ) + | |
' FROM ' + | |
describeResult.getName() | |
; | |
// return generic list of sobjects or typecast to expected type | |
List<SObject> records = Database.query( query ); | |
System.debug( records ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment