Get allowed fields for one object split by comma

PHOTO EMBED

Wed Jun 09 2021 09:32:01 GMT+0000 (UTC)

Saved by @rfeitor ##salesforce ##validate

/**
  * getAllAllowedFieldsForCurrentUser
  * @param objectAPI, Object Api Name
  * @return String.join(fieldList, ','), all the fields concatened, separated by ","
  */
private static string getAllAllowedFieldsForCurrentUser (string objectAPI) {
    return string.join(new List<String>(Schema.getGlobalDescribe().get(objectAPI).getDescribe().fields.getMap().keySet()), ',');
}
content_copyCOPY

Get allowed fields for one object split by comma, this can be use on a database query, for example