PropicSignifi/Query.apex

Allow user to config flexible field attributes when select all fields

HenryRLee opened this issue · 1 comments

So far Query.apex supports selectAllFields, selectCreatableFields and selectEditableFields. But indeed Salesforce has way more attributes in the DescribeFieldResult type (https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_methods_system_fields_describe.htm).

So my proposal is to add a new subclass named FieldSetting, which consists of the following fields:

public class FieldSetting {
    Boolean isAccessible;
    Boolean isAutoNumber;
    Boolean isCalculated;
    Boolean isCascadeDelete;
    Boolean isCaseSensitive;
    Boolean isCreateable;
    Boolean isCustom;
    Boolean isDefaultedOnCreate;
    Boolean isDependentPicklist;
    Boolean isExternalID;
    Boolean isFilterable;
    Boolean isFormulaTreatNullNumberAsZero;
    Boolean isGroupable;
    Boolean isHtmlFormatted;
    Boolean isIdLookup;
    Boolean isNameField;
    Boolean isNamePointing;
    Boolean isNillable;
    Boolean isPermissionable;
    Boolean isRestrictedDelete;
    Boolean isRestrictedPicklist;
    Boolean isSearchPrefilterable;
    Boolean isSortable;
    Boolean isUnique;
    Boolean isUpdateable;
    Boolean isWriteRequiresMasterRead;
}

Each of these fields matches an attribute in DescribeFieldResult.

In the meantime, allow selectAllFields to take FieldSetting as a parameter.

Query selectAllFields(FieldSetting setting) {}

Let's use an example to demonstrate this. Suppose a user wants to select all fields which are accessible and sortable, he may construct a FieldSetting object, and pass it to the selectAllFields method in Query:

FieldSetting setting = new FieldSetting();
setting.isAccessible = true;
setting.isSortable = true;

new Query('Account').selectAllFields(setting);

Then selectAllFields would select all the fields that matches the setting (accessible AND sortable).

The setting should have default values if user did not specify. isAccessible should be defaulted to be true, because it would be meaningless to select non-accessible fields. And the rest of the fields should be defaulted to be false.

To remain backward compatibility, we still need to preserve the selectCreatableFields(), selectEditableFields() and selectAllFields() methods.

Fixed in #46