In certain parts of our existing Apex code base, we've used dynamic soql in combination with object describe methods as a workaround to achieve the equivalent of SELECT * that's normally available in sql.
// This is the object for which we required data. Map<String, Schema.SObjectField> fieldMap = Opportunity.sObjectType.getDescribe().fields.getMap(); // Get all of the fields on the object Set<String> fieldNames = fieldMap.keySet(); // Build a Dynamic Query String. List<Opportunity> opps = Database.query('select ' + string.join(fieldNames, ',') + ' from Opportunity');
I'm aware that querying all fields off a record isn't recommended within Salesforce, and should be used carefully/sparingly. However, we have a couple objects with 20 fields or fewer where we really do need every single field on the object in order to support the page and user processes it is involved in, so setting up a scratch org with data would mean exporting all the field values from a set of existing records and importing them into the org.
Unfortunately sfdx force:data:tree:export doesn't allow us to use Apex in conjunction with the SOQL statement to allow us to use the workaround.
Any ideas for how to work around this?