Skip to content

Instantly share code, notes, and snippets.

@tehnrd
Created January 29, 2023 16:28
Show Gist options
  • Save tehnrd/eea95073ea54fed7a2b8dc0c45634cae to your computer and use it in GitHub Desktop.
Save tehnrd/eea95073ea54fed7a2b8dc0c45634cae to your computer and use it in GitHub Desktop.
Apex SOQL only Createable Fields
List<Schema.SObjectField> flds = Schema.sObjectType.Lead.fields.getmap().values();
List<String> selectFields = new List<String>();
for (Schema.SObjectField fld : flds) {
Schema.DescribeFieldResult fldDesc = fld.getDescribe();
if (fldDesc.isCreateable() == true) {
selectFields.add(fldDesc.getName());
}
}
String soql = 'SELECT ' + String.join(selectFields, ',') + ' FROM Lead';
system.debug(soql);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment