Skip to main content The Trailblazer Community will be unavailable from 2/1/2025 to 2/2/2025. Please plan your activities accordingly.

I have a method that loops through one map and adds relevant information from a another map.  

for(id opp : opps.keySet()){

id dg = opps.get(opp);

if (templates.containsKey(dg) ) {

list<npsp__Allocation__c> thisTemplate = templates.get(dg);

for (npsp__Allocation__c t : thisTemplate) {

t.npsp__Opportunity__c = opp;

toInsert.add(t);

system.debug('added: '+toInsert[toInsert.size()-1].npsp__Opportunity__c); // << ⌗1

}

}

}

system.debug('------------------ ');

for (npsp__Allocation__c a : toInsert ) system.debug(a.npsp__Opportunity__c); // << ⌗2

Looking at the output from the debug statements - the two ids are different, specificially one includes FF and the other includes FG.  However when interrogated again they're both FG.

User-added image

What's going on?  How do I fix this?  I have tried changing API version of the code - no luck.  
1 answer
  1. Jun 29, 2017, 8:08 PM

    in case others run into this type of issue in the future - the problem boiled down to passing values by reference vs. by value.

    t.npsp__Opportunity__c = opp;

    toInsert.add(t);

    instead of above - it was solved by createing a new npsp__Allocation__c and copying values to it, then adding it.
0/9000