@@ -48,12 +48,12 @@ public with sharing class CollectionFunctions {
4848 }
4949 }
5050
51- private static Environment getEnvironmentFromObject (Object currentVal ) {
51+ private static Environment getEnvironmentFromObject (Environment parentEnvironment , Object currentVal ) {
5252 Environment env ;
5353 if (currentVal instanceof SObject ) {
54- env = new Environment ((SObject ) currentVal );
54+ env = new Environment (parentEnvironment , (SObject ) currentVal );
5555 } else {
56- env = new Environment ();
56+ env = new Environment (parentEnvironment );
5757 }
5858 return env ;
5959 }
@@ -118,7 +118,7 @@ public with sharing class CollectionFunctions {
118118 List <Object > result = new List <Object >();
119119 for (Integer i = 0 ; i < childrenAsList .size (); i ++ ) {
120120 Object child = childrenAsList .get (i );
121- Environment env = getEnvironmentFromObject (child );
121+ Environment env = getEnvironmentFromObject (this . interpreter . getEnvironment (), child );
122122 env .define (' $current' , child );
123123 env .define (' $index' , i );
124124 env .define (' $total' , childrenAsList .size ());
@@ -170,7 +170,7 @@ public with sharing class CollectionFunctions {
170170 List <Object > result = new List <Object >();
171171 for (Integer i = 0 ; i < childrenAsList .size (); i ++ ) {
172172 Object child = childrenAsList .get (i );
173- Environment env = getEnvironmentFromObject (child );
173+ Environment env = getEnvironmentFromObject (this . interpreter . getEnvironment (), child );
174174
175175 env .define (' $current' , child );
176176 env .define (' $index' , i );
@@ -774,7 +774,7 @@ public with sharing class CollectionFunctions {
774774 // The result of the expression will be the new value.
775775 Object accumulator = initialValue ;
776776 for (Object currentVal : listVal ) {
777- Environment env = getEnvironmentFromObject (currentVal );
777+ Environment env = getEnvironmentFromObject (this . interpreter . getEnvironment (), currentVal );
778778 env .define (' $current' , currentVal );
779779 env .define (' $accumulator' , accumulator );
780780 Interpreter interpreter = new Interpreter (env );
@@ -902,7 +902,7 @@ public with sharing class CollectionFunctions {
902902 // Loop through each element in the list, evaluating the
903903 // expression with the current value (as $current) being looped.
904904 for (Object currentVal : listVal ) {
905- Environment env = getEnvironmentFromObject (currentVal );
905+ Environment env = getEnvironmentFromObject (this . interpreter . getEnvironment (), currentVal );
906906 env .define (' $current' , currentVal );
907907 Interpreter interpreter = new Interpreter (env );
908908 Object result = interpreter .interpret (expr );
@@ -999,7 +999,7 @@ public with sharing class CollectionFunctions {
999999 // Loop through each element in the list, evaluating the
10001000 // expression with the current value (as $current) being looped.
10011001 for (Object currentVal : listVal ) {
1002- Environment env = getEnvironmentFromObject (currentVal );
1002+ Environment env = getEnvironmentFromObject (this . interpreter . getEnvironment (), currentVal );
10031003 env .define (' $current' , currentVal );
10041004 Interpreter interpreter = new Interpreter (env );
10051005 Object result = interpreter .interpret (expr );
@@ -1059,7 +1059,7 @@ public with sharing class CollectionFunctions {
10591059 // expression with the current value (as $current) being looped.
10601060 List <Object > result = new List <Object >();
10611061 for (Object currentVal : listVal ) {
1062- Environment env = getEnvironmentFromObject (currentVal );
1062+ Environment env = getEnvironmentFromObject (this . interpreter . getEnvironment (), currentVal );
10631063 env .define (' $current' , currentVal );
10641064 Interpreter interpreter = new Interpreter (env );
10651065 Object evaluated = interpreter .interpret (expr );
@@ -1118,7 +1118,7 @@ public with sharing class CollectionFunctions {
11181118 // Loop through each element in the list, evaluating the
11191119 // expression with the current value (as $current) being looped.
11201120 for (Object currentVal : listVal ) {
1121- Environment env = getEnvironmentFromObject (currentVal );
1121+ Environment env = getEnvironmentFromObject (this . interpreter . getEnvironment (), currentVal );
11221122 env .define (' $current' , currentVal );
11231123 Interpreter interpreter = new Interpreter (env );
11241124 Object result = interpreter .interpret (expr );
@@ -1254,7 +1254,7 @@ public with sharing class CollectionFunctions {
12541254 // expression with the current value (as $current) being looped.
12551255 for (Integer i = listVal .size () - 1 ; i >= 0 ; i -- ) {
12561256 Object currentVal = listVal .get (i );
1257- Environment env = getEnvironmentFromObject (currentVal );
1257+ Environment env = getEnvironmentFromObject (this . interpreter . getEnvironment (), currentVal );
12581258 env .define (' $current' , currentVal );
12591259 Interpreter interpreter = new Interpreter (env );
12601260 Object result = interpreter .interpret (expr );
@@ -1361,7 +1361,7 @@ public with sharing class CollectionFunctions {
13611361 List <Object > listVal = (List <Object >) listObj ;
13621362 for (Integer i = 0 ; i < listVal .size (); i ++ ) {
13631363 Object currentVal = listVal .get (i );
1364- Environment env = getEnvironmentFromObject (currentVal );
1364+ Environment env = getEnvironmentFromObject (this . interpreter . getEnvironment (), currentVal );
13651365 env .define (' $current' , currentVal );
13661366 Interpreter interpreter = new Interpreter (env );
13671367 Object result = interpreter .interpret (expr );
@@ -1475,7 +1475,7 @@ public with sharing class CollectionFunctions {
14751475 List <Object > listVal = (List <Object >) listObj ;
14761476 for (Integer i = 0 ; i < listVal .size (); i ++ ) {
14771477 Object currentVal = listVal .get (i );
1478- Environment env = getEnvironmentFromObject (currentVal );
1478+ Environment env = getEnvironmentFromObject (this . interpreter . getEnvironment (), currentVal );
14791479 env .define (' $current' , currentVal );
14801480 Interpreter interpreter = new Interpreter (env );
14811481 Object result = interpreter .interpret (expr );
@@ -1629,7 +1629,7 @@ public with sharing class CollectionFunctions {
16291629 Object acc = null ;
16301630 for (Integer i = 0 ; i < values .size (); i ++ ) {
16311631 Object current = values .get (i );
1632- Environment env = getEnvironmentFromObject (current );
1632+ Environment env = getEnvironmentFromObject (this . interpreter . getEnvironment (), current );
16331633
16341634 env .define (' $current' , current );
16351635 env .define (' $key' , key );
@@ -1676,7 +1676,7 @@ public with sharing class CollectionFunctions {
16761676 Expr expr = arguments .get (1 );
16771677 Map <Object , Object > result = new Map <Object , Object >();
16781678 for (Object currentVal : listVal ) {
1679- Environment env = getEnvironmentFromObject (currentVal );
1679+ Environment env = getEnvironmentFromObject (this . interpreter . getEnvironment (), currentVal );
16801680 env .define (' $current' , currentVal );
16811681 Interpreter interpreter = new Interpreter (env );
16821682 Object key = interpreter .interpret (expr );
@@ -1719,7 +1719,7 @@ public with sharing class CollectionFunctions {
17191719 Expr expr = arguments .get (1 );
17201720 Map <Object , List <Object >> result = new Map <Object , List <Object >>();
17211721 for (Object currentVal : listVal ) {
1722- Environment env = getEnvironmentFromObject (currentVal );
1722+ Environment env = getEnvironmentFromObject (this . interpreter . getEnvironment (), currentVal );
17231723 env .define (' $current' , currentVal );
17241724 Interpreter interpreter = new Interpreter (env );
17251725 Object key = interpreter .interpret (expr );
0 commit comments