Skip to content

Selector Field Injection

John Storey edited this page May 16, 2020 · 8 revisions

Background

All of an SObject's responsibility should be assumed by a single package, which includes the selector.

Situation

A downstream package has added a field. In this case, the Marketing implementation has added a "Slogan" field to the Account. Since the Account selector resides in the Common package and the new field resides in the Marketing package, how would the selector include the upstream package's new field.

Answer

Via custom metadata, inject the new field into the field list generated by the selector factory infrastructure.

Details

  • During instantiation, the ApplicationSObjectSelector, which extends fflib_SObjectSelector, reads the SelectorConfig_FieldSetInclusion custom metadata type for records related to the Account.
  • From the resulting field sets, the associated fields are added to the set of desired fields.
  • All desired fields are added to the generated SOQL and returned to the consumer.

References: