|
| 1 | +# New domain structure |
| 2 | +The new domain structure allows more flexibility of the object type a domain can contain. |
| 3 | +This allows for the creation of compound-domains and domains of data-classes. |
| 4 | + |
| 5 | +It also splits the functionality into a Domain Model [as described by Martin Fowler](https://www.martinfowler.com/eaaCatalog/domainModel.html) and a separate trigger handler. |
| 6 | +This helps to structure the code better and makes it more clear which Apex code should be in the domain and which in the trigger handler. |
| 7 | + |
| 8 | + |
| 9 | + |
| 10 | +## Previous interface and implementation structure |
| 11 | +| Interfaces | Implementation | Description | |
| 12 | +|:---|:---|:---| |
| 13 | +| fflib_ISObjectDomain | fflib_SObjectDomain | Used as Domain and trigger handler |
| 14 | + |
| 15 | + |
| 16 | +## New interface and implementation structure |
| 17 | +| Interfaces | Implementation | Description | |
| 18 | +|:---|:---|:---| |
| 19 | +| fflib_IDomain | | Generic identifier for domains |
| 20 | +| fflib_IObjects | fflib_Objects | Domains constructed with Objects, e.g. data-classes |
| 21 | +| fflib_ISObjects | fflib_SObjects | Domain containing SObjectTypes, e.g. Accounts, Contacts |
| 22 | +| fflib_ISObjectDomain | fflib_SObjectDomain | Used for trigger handlers and for legacy domains |
| 23 | + |
| 24 | +See [this PR](https://github.com/apex-enterprise-patterns/fflib-apex-common/pull/300) for a detailed overview |
| 25 | +of all the code changes which were part of this change. |
| 26 | + |
| 27 | +The [fflib-apex-common-samplecode](https://github.com/apex-enterprise-patterns/fflib-apex-common-samplecode) |
| 28 | +also includes examples on how to structure the change into the |
| 29 | +[new domain](https://github.com/apex-enterprise-patterns/fflib-apex-common-samplecode/blob/master/sfdx-source/apex-common-samplecode/main/classes/domains/Accounts.cls) |
| 30 | +and [trigger handler](https://github.com/apex-enterprise-patterns/fflib-apex-common-samplecode/blob/master/sfdx-source/apex-common-samplecode/main/classes/triggerHandlers/OpportunitiesTriggerHandler.cls) |
| 31 | + |
| 32 | +## Known issues and how to resolve them |
| 33 | + |
| 34 | + |
| 35 | +### _Issue:_ Ambiguous method signature: void setMock(MyDomainClass) |
| 36 | +This happens when you try to mock an old domain class which is extended from fflib_SObjectDomain. |
| 37 | +```apex |
| 38 | +Application.Domain.setMock(mockAssetsDomain); // <<== generates Ambiguous method signature: void setMock |
| 39 | +``` |
| 40 | +The issue can be resolved by casting the mock implementation to fflib_ISObjectDomain: |
| 41 | +> Application.Domain.setMock( **(fflib_ISObjectDomain)** mockAssetsDomain); |
| 42 | +
|
| 43 | +[See this issue report for more information](https://github.com/apex-enterprise-patterns/fflib-apex-common/issues/347) |
| 44 | + |
| 45 | + |
| 46 | +### _Issue:_ Illegal assignment from fflib_Domain to fflib_ISObjectDomain |
| 47 | +The `newInstance` method signature of the Application Domain Factory (fflib_Application.DomainFactory) has changed into: |
| 48 | +>public **fflib_IDomain** newInstance(***); |
| 49 | +
|
| 50 | +If you have: |
| 51 | +```apex |
| 52 | +fflib_ISObjectDomain domain = Application.Domain.newInstance(sObjIds); |
| 53 | +``` |
| 54 | +You need to change that into: |
| 55 | +> fflib_ISObjectDomain domain = **(fflib_ISObjectDomain)** Application.Domain.newInstance(sObjIds); |
| 56 | +
|
| 57 | +[See this issue report for more information](https://github.com/apex-enterprise-patterns/fflib-apex-common/issues/346) |
0 commit comments