Skip to content

Commit a693e59

Browse files
committed
#162: updated commets, updated api version
1 parent cf94fb7 commit a693e59

File tree

4 files changed

+36
-46
lines changed

4 files changed

+36
-46
lines changed

fflib/src/classes/fflib_QueryFactory.cls

Lines changed: 30 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -338,9 +338,10 @@ public class fflib_QueryFactory { //No explicit sharing declaration - inherit fr
338338
this.order.add(o);
339339
return this;
340340
}
341+
341342
/**
342343
* @param o an instance of {@link fflib_QueryFactory.Ordering} to remove all existing (for instance defaults) and be added to the query's ORDER BY clause.
343-
**/
344+
**/
344345
public fflib_QueryFactory setOrdering(Ordering o){
345346
this.order = new List<Ordering>{ o };
346347
return this;
@@ -547,7 +548,7 @@ public class fflib_QueryFactory { //No explicit sharing declaration - inherit fr
547548
**/
548549
public fflib_QueryFactory addOrdering(String fieldName, SortOrder direction){
549550
order.add(
550-
new Ordering(getFieldToken(fieldName), direction)
551+
new Ordering(getFieldPath(fieldName), direction)
551552
);
552553
return this;
553554
}
@@ -566,83 +567,72 @@ public class fflib_QueryFactory { //No explicit sharing declaration - inherit fr
566567
**/
567568
public fflib_QueryFactory addOrdering(SObjectField field, SortOrder direction){
568569
order.add(
569-
new Ordering(getFieldPath(fieldName), direction)
570+
new Ordering(getFieldTokenPath(field), direction)
570571
);
571572
return this;
572573
}
574+
573575
/**
574-
* Remove existing ordering and set a field to be sorted on. This may be a direct field or a field
576+
* Remove existing ordering and set a field to be sorted on. This may be a direct field or a field
575577
* related through an object lookup or master-detail relationship.
576578
* Use the set to store unique field names, since we only want to sort
577579
* by the same field one time. The sort expressions are stored in a list
578580
* so that they are applied to the SOQL in the same order that they
579-
* were added in.
581+
* were added in.
580582
* @param fieldName The string value of the field to be sorted on
581583
* @param SortOrder the direction to be sorted on (ASCENDING or DESCENDING)
582584
* @param nullsLast whether to sort null values last (NULLS LAST keyword included).
583-
**/
584-
public fflib_QueryFactory setOrdering(String fieldName, SortOrder direction, Boolean nullsLast){
585+
**/
586+
public fflib_QueryFactory setOrdering(String fieldName, SortOrder direction, Boolean nullsLast){
585587
Ordering ordr = new Ordering(getFieldPath(fieldName), direction, nullsLast);
586588
return setOrdering(ordr);
587-
}
589+
}
588590

589-
/**
590-
* Remove existing ordering and set a field to be sorted on. This may be a direct field or a field
591-
* related through an object lookup or master-detail relationship.
591+
/**
592+
* Remove existing ordering and set a field to be sorted on. This may be a direct field or a field
593+
* related through an object lookup or masterdetail relationship.
592594
* Use the set to store unique field names, since we only want to sort
593595
* by the same field one time. The sort expressions are stored in a list
594596
* so that they are applied to the SOQL in the same order that they
595-
* were added in.
597+
* were added in.
596598
* @param field The SObjectfield to sort. This can only be a direct reference.
597599
* @param SortOrder the direction to be sorted on (ASCENDING or DESCENDING)
598600
* @param nullsLast whether to sort null values last (NULLS LAST keyword included).
599601
**/
600-
<<<<<<< HEAD
601-
public fflib_QueryFactory addOrdering(SObjectField field, SortOrder direction){
602-
order.add(
603-
new Ordering(getFieldTokenPath(field), direction)
604-
);
605-
return this;
606-
=======
607-
public fflib_QueryFactory setOrdering(SObjectField field, SortOrder direction, Boolean nullsLast){
608-
Ordering ordr = new Ordering(field, direction, nullsLast);
602+
public fflib_QueryFactory setOrdering(SObjectField field, SortOrder direction, Boolean nullsLast){
603+
Ordering ordr = new Ordering(getFieldTokenPath(field), direction, nullsLast);
609604
return setOrdering(ordr);
610-
>>>>>>> #162: updated setOrderings for methods with string field name parameter
611-
}
605+
}
612606

613-
/**
614-
* Remove existing ordering and set a field to be sorted on. This may be a direct field or a field
607+
/**
608+
* Remove existing ordering and set a field to be sorted on. This may be a direct field or a field
615609
* related through an object lookup or master-detail relationship.
616610
* Use the set to store unique field names, since we only want to sort
617611
* by the same field one time. The sort expressions are stored in a list
618612
* so that they are applied to the SOQL in the same order that they
619-
* were added in.
620-
* The "NULLS FIRST" keywords will be included by default. If "NULLS LAST"
621-
* is required, use one of the overloaded addOrdering methods which include this parameter.
613+
* were added in.
622614
* @param fieldName The string value of the field to be sorted on
623615
* @param SortOrder the direction to be sorted on (ASCENDING or DESCENDING)
624-
**/
625-
public fflib_QueryFactory setOrdering(String fieldName, SortOrder direction){
616+
**/
617+
public fflib_QueryFactory setOrdering(String fieldName, SortOrder direction){
626618
Ordering ordr = new Ordering(getFieldPath(fieldName), direction);
627619
return setOrdering(ordr);
628-
}
620+
}
629621

630-
/**
631-
* Remove existing ordering and set a field to be sorted on. This may be a direct field or a field
632-
* related through an object lookup or master-detail relationship.
622+
/**
623+
* Remove existing ordering and set a field to be sorted on. This may be a direct field or a field
624+
* related through an object lookup or masterdetail relationship.
633625
* Use the set to store unique field names, since we only want to sort
634626
* by the same field one time. The sort expressions are stored in a list
635627
* so that they are applied to the SOQL in the same order that they
636-
* were added in.
637-
* The "NULLS FIRST" keywords will be included by default. If "NULLS LAST"
638-
* is required, use one of the overloaded addOrdering methods which include this parameter.
628+
* were added in.
639629
* @param field The SObjectfield to sort. This can only be a direct reference.
640630
* @param SortOrder the direction to be sorted on (ASCENDING or DESCENDING)
641631
**/
642-
public fflib_QueryFactory setOrdering(SObjectField field, SortOrder direction){
643-
Ordering ordr = new Ordering(field, direction);
632+
public fflib_QueryFactory setOrdering(SObjectField field, SortOrder direction){
633+
Ordering ordr = new Ordering(getFieldTokenPath(field), direction);
644634
return setOrdering(ordr);
645-
}
635+
}
646636

647637
/**
648638
* Convert the values provided to this instance into a full SOQL string for use with Database.query
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<ApexClass xmlns="http://soap.sforce.com/2006/04/metadata">
3-
<apiVersion>37.0</apiVersion>
3+
<apiVersion>42.0</apiVersion>
44
<status>Active</status>
55
</ApexClass>

fflib/src/classes/fflib_QueryFactoryTest.cls

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -161,23 +161,23 @@ private class fflib_QueryFactoryTest {
161161
System.assert( Pattern.matches('SELECT.*Email.*FROM.*',query), 'Expected Name field in query, got '+query);
162162
}
163163

164-
@isTest
164+
@isTest(isParallel=true)
165165
static void setOrdering_ReplacesPreviousOrderingsWithExpectedOrdering(){
166166
fflib_QueryFactory qf = new fflib_QueryFactory(Contact.SObjectType);
167167
qf.selectField('name');
168168
qf.selectField('email');
169169
qf.setCondition( 'name = \'test\'' );
170-
170+
171171
//test base method with ordeting by OwnerId Descending
172172
qf.setOrdering( new fflib_QueryFactory.Ordering('Contact','OwnerId',fflib_QueryFactory.SortOrder.DESCENDING) );
173-
173+
174174
System.assertEquals(1, qf.getOrderings().size(), 'Unexpected order size - setOrder should replace default Orderings');
175175
System.assertEquals(Contact.OwnerId.getDescribe().getName(), qf.getOrderings()[0].getField(), 'Unexpected order field - should have been resolved from the field OwnerId');
176176
System.assertEquals(fflib_QueryFactory.SortOrder.DESCENDING, qf.getOrderings()[0].getDirection(), 'Unexpected order direction.');
177177

178178
//test method overload with ordering by LastModifiedDate Ascending
179179
qf.setOrdering('LastModifiedDate', fflib_QueryFactory.SortOrder.ASCENDING, true);
180-
180+
181181
System.assertEquals(1, qf.getOrderings().size(), 'Unexpected order size - setOrder should replace previous Orderings');
182182
System.assertEquals(Contact.LastModifiedDate.getDescribe().getName(), qf.getOrderings()[0].getField(), 'Unexpected order field - should have been resolved from the field LastModifiedDate');
183183
System.assertEquals(fflib_QueryFactory.SortOrder.ASCENDING, qf.getOrderings()[0].getDirection(), 'Unexpected order direction.');
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<ApexClass xmlns="http://soap.sforce.com/2006/04/metadata">
3-
<apiVersion>37.0</apiVersion>
3+
<apiVersion>42.0</apiVersion>
44
<status>Active</status>
55
</ApexClass>

0 commit comments

Comments
 (0)