Field¶
The Field class represents a property that a record may have. It is analogous to a table column, or—in Salesforce—an object field.
We refer to Fields when we are inspecting the Schema, or shape, of records for a particular table or object. You will encounter this Valence class if you are implementing the SchemaAdapter interface.
Fields are constructed using a builder pattern that uses a fluent interface to make it simple to construct Field instances with varying degrees of complexity.
You get a FieldBuilder by calling Field.create() and passing the API name of the Field you are constructing. This is the only required property, but it’s an important one. This string value is expected to match exactly to what is used on the records that will be retrieved from, and given to, your Adapter.
Simple Field Example¶
valence.Field firstNameField = valence.Field.create('firstName').withLabel('First Name').build();
More Complex Field Example¶
valence.Field startDateField = valence.Field.create('startDate')
.withLabel('Start Date')
.withDescription('What day this subscription was first activated')
.withType('string')
.withFormat('yyyy-MM-dd')
.withExampleValue('2017-01-24')
.build();
Properties¶
Data Type | Class Property | Builder Method | Description |
---|---|---|---|
String | name | Required. Expected to match actual record field names. | |
String | label | withLabel(String label) | User-friendly label for this field. |
String | description | withDescription(String description) | Description of the field’s purpose. |
String | exampleValue | withExampleValue(String exampleValue) | An example value to help give a user context. Truncates to 20 characters. |
String | defaultValue | withDefaultValue(String defaultValue) | The default value that will be used if this field is left blank. Truncates to 20 characters. |
String | type | withType(String type) | The data type of the field. Truncates to 20 characters. |
String | format | withFormat(String format) | The format of the value, if applicable. Truncates to 20 characters. |
Boolean | isRequired | setRequired(Boolean isRequired) | True if this field must be present on every record. |
Boolean | isCreateable | setCreateable(Boolean isCreateable) | True if this field can be set on record creation. |
Boolean | isUpdateable | setEditable(Boolean isEditable) | True if this field can be set on record update. |
Boolean | isEditable | setEditable(Boolean isEditable) | True if either isCreateable or isUpdateable have been set. Can also be set independently. |
Boolean | isMap | setMap(Boolean isMap, Boolean isLazy) | True if this Field in the schema is a Map of other Fields (so, keyed) |
Boolean | isList | setList(Boolean isList, Boolean isLazy) | True if this Field is a List of other Fields (no keys) |
Boolean | isLazy | True if this List/Map is not going to have children set right now, but could have them lazily loaded later |