Skip to content

Commit fbc113f

Browse files
Merge branch 'master' into feature/MoreDomainMethods
2 parents 5220da6 + 1e5eb56 commit fbc113f

12 files changed

+270
-15
lines changed

sfdx-source/apex-common/main/classes/fflib_Application.cls

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public virtual class fflib_Application
3434
/**
3535
* Class implements a Unit of Work factory
3636
**/
37-
public virtual class UnitOfWorkFactory
37+
public virtual class UnitOfWorkFactory implements fflib_IUnitOfWorkFactory
3838
{
3939
protected List<SObjectType> m_objectTypes;
4040
protected fflib_ISObjectUnitOfWork m_mockUow;
@@ -122,7 +122,7 @@ public virtual class fflib_Application
122122
/**
123123
* Simple Service Factory implementation
124124
**/
125-
public virtual class ServiceFactory
125+
public virtual class ServiceFactory implements fflib_IServiceFactory
126126
{
127127
protected Map<Type, Type> m_serviceInterfaceTypeByServiceImplType;
128128

@@ -178,7 +178,7 @@ public virtual class fflib_Application
178178
/**
179179
* Class implements a Selector class factory
180180
**/
181-
public virtual class SelectorFactory
181+
public virtual class SelectorFactory implements fflib_ISelectorFactory
182182
{
183183
protected Map<SObjectType, Type> m_sObjectBySelectorType;
184184
protected Map<SObjectType, fflib_ISObjectSelector> m_sObjectByMockSelector;
@@ -280,7 +280,7 @@ public virtual class fflib_Application
280280
/**
281281
* Class implements a Domain class factory
282282
**/
283-
public virtual class DomainFactory
283+
public virtual class DomainFactory implements fflib_IDomainFactory
284284
{
285285
protected fflib_Application.SelectorFactory m_selectorFactory;
286286

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/**
2+
* Copyright (c), FinancialForce.com, inc
3+
* All rights reserved.
4+
*
5+
* Redistribution and use in source and binary forms, with or without modification,
6+
* are permitted provided that the following conditions are met:
7+
*
8+
* - Redistributions of source code must retain the above copyright notice,
9+
* this list of conditions and the following disclaimer.
10+
* - Redistributions in binary form must reproduce the above copyright notice,
11+
* this list of conditions and the following disclaimer in the documentation
12+
* and/or other materials provided with the distribution.
13+
* - Neither the name of the FinancialForce.com, inc nor the names of its contributors
14+
* may be used to endorse or promote products derived from this software without
15+
* specific prior written permission.
16+
*
17+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
18+
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19+
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
20+
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
21+
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22+
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
23+
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24+
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25+
**/
26+
public interface fflib_IDomainFactory
27+
{
28+
fflib_IDomain newInstance(Set<Id> recordIds);
29+
fflib_IDomain newInstance(List<SObject> records);
30+
fflib_IDomain newInstance(List<Object> objects, Object objectType);
31+
fflib_IDomain newInstance(List<SObject> records, SObjectType domainSObjectType);
32+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<ApexClass xmlns="http://soap.sforce.com/2006/04/metadata">
3+
<apiVersion>51.0</apiVersion>
4+
<status>Active</status>
5+
</ApexClass>
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/**
2+
* Copyright (c), FinancialForce.com, inc
3+
* All rights reserved.
4+
*
5+
* Redistribution and use in source and binary forms, with or without modification,
6+
* are permitted provided that the following conditions are met:
7+
*
8+
* - Redistributions of source code must retain the above copyright notice,
9+
* this list of conditions and the following disclaimer.
10+
* - Redistributions in binary form must reproduce the above copyright notice,
11+
* this list of conditions and the following disclaimer in the documentation
12+
* and/or other materials provided with the distribution.
13+
* - Neither the name of the FinancialForce.com, inc nor the names of its contributors
14+
* may be used to endorse or promote products derived from this software without
15+
* specific prior written permission.
16+
*
17+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
18+
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19+
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
20+
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
21+
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22+
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
23+
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24+
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25+
**/
26+
public interface fflib_ISelectorFactory
27+
{
28+
fflib_ISObjectSelector newInstance(SObjectType sObjectType);
29+
List<SObject> selectById(Set<Id> recordIds);
30+
List<SObject> selectByRelationship(List<SObject> relatedRecords, SObjectField relationshipField);
31+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<ApexClass xmlns="http://soap.sforce.com/2006/04/metadata">
3+
<apiVersion>51.0</apiVersion>
4+
<status>Active</status>
5+
</ApexClass>
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/**
2+
* Copyright (c), FinancialForce.com, inc
3+
* All rights reserved.
4+
*
5+
* Redistribution and use in source and binary forms, with or without modification,
6+
* are permitted provided that the following conditions are met:
7+
*
8+
* - Redistributions of source code must retain the above copyright notice,
9+
* this list of conditions and the following disclaimer.
10+
* - Redistributions in binary form must reproduce the above copyright notice,
11+
* this list of conditions and the following disclaimer in the documentation
12+
* and/or other materials provided with the distribution.
13+
* - Neither the name of the FinancialForce.com, inc nor the names of its contributors
14+
* may be used to endorse or promote products derived from this software without
15+
* specific prior written permission.
16+
*
17+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
18+
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19+
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
20+
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
21+
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22+
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
23+
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24+
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25+
**/
26+
public interface fflib_IServiceFactory
27+
{
28+
Object newInstance(Type serviceInterfaceType);
29+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<ApexClass xmlns="http://soap.sforce.com/2006/04/metadata">
3+
<apiVersion>51.0</apiVersion>
4+
<status>Active</status>
5+
</ApexClass>
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/**
2+
* Copyright (c), FinancialForce.com, inc
3+
* All rights reserved.
4+
*
5+
* Redistribution and use in source and binary forms, with or without modification,
6+
* are permitted provided that the following conditions are met:
7+
*
8+
* - Redistributions of source code must retain the above copyright notice,
9+
* this list of conditions and the following disclaimer.
10+
* - Redistributions in binary form must reproduce the above copyright notice,
11+
* this list of conditions and the following disclaimer in the documentation
12+
* and/or other materials provided with the distribution.
13+
* - Neither the name of the FinancialForce.com, inc nor the names of its contributors
14+
* may be used to endorse or promote products derived from this software without
15+
* specific prior written permission.
16+
*
17+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
18+
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19+
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
20+
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
21+
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22+
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
23+
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24+
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25+
**/
26+
public interface fflib_IUnitOfWorkFactory
27+
{
28+
fflib_ISObjectUnitOfWork newInstance();
29+
fflib_ISObjectUnitOfWork newInstance(fflib_SObjectUnitOfWork.IDML dml);
30+
fflib_ISObjectUnitOfWork newInstance(List<SObjectType> objectTypes);
31+
fflib_ISObjectUnitOfWork newInstance(List<SObjectType> objectTypes, fflib_SObjectUnitOfWork.IDML dml);
32+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<ApexClass xmlns="http://soap.sforce.com/2006/04/metadata">
3+
<apiVersion>51.0</apiVersion>
4+
<status>Active</status>
5+
</ApexClass>

sfdx-source/apex-common/main/classes/fflib_QueryFactory.cls

Lines changed: 35 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ public class fflib_QueryFactory { //No explicit sharing declaration - inherit fr
8484
private Schema.ChildRelationship relationship;
8585
private Map<Schema.ChildRelationship, fflib_QueryFactory> subselectQueryMap;
8686

87-
private String getFieldPath(String fieldName){
87+
private String getFieldPath(String fieldName, Schema.sObjectType relatedSObjectType){
8888
if(!fieldName.contains('.')){ //single field
8989
Schema.SObjectField token = fflib_SObjectDescribe.getDescribe(table).getField(fieldName.toLowerCase());
9090
if(token == null)
@@ -107,8 +107,21 @@ public class fflib_QueryFactory { //No explicit sharing declaration - inherit fr
107107
fflib_SecurityUtils.checkFieldIsReadable(lastSObjectType, token);
108108
}
109109

110-
if(token != null && i.hasNext() && tokenDescribe.getSoapType() == Schema.SoapType.ID){
111-
lastSObjectType = tokenDescribe.getReferenceTo()[0]; //if it's polymorphic doesn't matter which one we get
110+
if (token != null && i.hasNext() && tokenDescribe.getSoapType() == Schema.SoapType.ID) {
111+
List<Schema.sObjectType> relatedObjs = tokenDescribe.getReferenceTo(); //if it's polymorphic, it matters which one we use - i.e. Lead.Owner is GROUP|USER and each has different fields.
112+
113+
if (relatedObjs.size() == 1 || relatedSObjectType == null) {
114+
lastSObjectType = relatedObjs[0]; //caller did not specify the one to use or there's only one so use the first one
115+
}
116+
else{
117+
for (Schema.sObjectType sot : relatedObjs) {
118+
if (fflib_SObjectDescribe.getDescribe(sot).getDescribe().getSObjectType() == relatedSObjectType) {
119+
lastSObjectType = sot;
120+
break;
121+
}
122+
}
123+
}
124+
112125
fieldPath.add(tokenDescribe.getRelationshipName());
113126
}else if(token != null && !i.hasNext()){
114127
fieldPath.add(tokenDescribe.getName());
@@ -122,6 +135,10 @@ public class fflib_QueryFactory { //No explicit sharing declaration - inherit fr
122135

123136
return String.join(fieldPath,'.');
124137
}
138+
139+
private String getFieldPath(String fieldName) {
140+
return this.getFieldPath(fieldName, null);
141+
}
125142

126143
@TestVisible
127144
private static String getFieldTokenPath(Schema.SObjectField field){
@@ -197,16 +214,27 @@ public class fflib_QueryFactory { //No explicit sharing declaration - inherit fr
197214
this.sortSelectFields = doSort;
198215
return this;
199216
}
200-
201217
/**
202218
* Selects a single field from the SObject specified in {@link #table}.
203219
* Selecting fields is idempotent, if this field is already selected calling this method will have no additional impact.
204220
* @param fieldName the API name of the field to add to the query's SELECT clause.
205221
**/
206222
public fflib_QueryFactory selectField(String fieldName){
207-
fields.add( getFieldPath(fieldName) );
223+
fields.add( getFieldPath(fieldName, null) );
224+
return this;
225+
}
226+
227+
/**
228+
* Selects a single field from the SObject specified in {@link #table}.
229+
* Selecting fields is idempotent, if this field is already selected calling this method will have no additional impact.
230+
* @param fieldName the API name of the field to add to the query's SELECT clause.
231+
* @param relatedSObjectType the related sObjectType to resolve polymorphic object fields.
232+
**/
233+
public fflib_QueryFactory selectField(String fieldName, Schema.sOBjectType relatedObjectType) {
234+
fields.add(getFieldPath(fieldName, relatedObjectType));
208235
return this;
209-
}
236+
}
237+
210238
/**
211239
* Selects a field, avoiding the possible ambiguity of String API names.
212240
* @see #selectField(String)
@@ -760,6 +788,7 @@ public class fflib_QueryFactory { //No explicit sharing declaration - inherit fr
760788
this.setMessage( 'Invalid field \''+fieldName+'\' for object \''+objectType+'\'' );
761789
}
762790
}
791+
763792
public class InvalidFieldSetException extends Exception{}
764793
public class NonReferenceFieldException extends Exception{}
765794
public class InvalidSubqueryRelationshipException extends Exception{}

0 commit comments

Comments
 (0)