@@ -352,21 +352,24 @@ public virtual inherited sharing class SOQL implements Queryable {
352352 Mockable thenReturn (Integer count );
353353 }
354354
355- // Backward support
355+ // Backward support - it's going to be removed in the future
356356
357357 @TestVisible // deprecated
358358 private static void setMock (String mockId , SObject record ) {
359- mock (mockId ).thenReturn (record );
359+ queryIdToMock .put (mockId , new SoqlMock ().skipStrippingAdditionalPlainFields ());
360+ queryIdToMock .get (mockId ).thenReturn (record );
360361 }
361362
362363 @TestVisible // deprecated
363364 private static void setMock (String mockId , List <SObject > records ) {
364- mock (mockId ).thenReturn (records );
365+ queryIdToMock .put (mockId , new SoqlMock ().skipStrippingAdditionalPlainFields ());
366+ queryIdToMock .get (mockId ).thenReturn (records );
365367 }
366368
367369 @TestVisible // deprecated
368370 private static void setCountMock (String mockId , Integer amount ) {
369- mock (mockId ).thenReturn (amount );
371+ queryIdToMock .put (mockId , new SoqlMock ().skipStrippingAdditionalPlainFields ());
372+ queryIdToMock .get (mockId ).thenReturn (amount );
370373 }
371374
372375 // Implementation
@@ -2140,10 +2143,16 @@ public virtual inherited sharing class SOQL implements Queryable {
21402143 this .countMock .set (count );
21412144 return this ;
21422145 }
2146+
2147+ public SoqlMock skipStrippingAdditionalPlainFields () {
2148+ this .sObjectMock .stripAdditionalPlainFields = false ;
2149+ return this ;
2150+ }
21432151 }
21442152
21452153 public class SObjectMock {
21462154 private List <SObject > mockedRecords = new List <SObject >();
2155+ public Boolean stripAdditionalPlainFields = true ;
21472156
21482157 public void add (SObject record ) {
21492158 this .mockedRecords .add (record );
@@ -2158,7 +2167,7 @@ public virtual inherited sharing class SOQL implements Queryable {
21582167 throw new QueryException (' Aggregate functions mocking is currently not supported.' );
21592168 }
21602169
2161- if (fields .relationshipFields .isEmpty () && fields .functionsFields .isEmpty ()) {
2170+ if (this . stripAdditionalPlainFields && fields .relationshipFields .isEmpty () && fields .functionsFields .isEmpty ()) {
21622171 this .mockedRecords = this .stripAdditionalPlainFields (fields .plainFields .get ());
21632172 }
21642173
0 commit comments