3

noticing some odd behavior on this test I wrote. Seems really strange but when I do this assert by itself it fails:

    List<String> newGmSharedSnapshots = new List<String>();
    for(CS_Contract_Snapshot__Share share: newGmShares) {
        newGmSharedSnapshots.add(share.ParentId);
        system.assert(newGmSharedSnapshots.contains(share.ParentId))

    }

However, when I add this debug log prior to assertion, the test passes:

    List<String> newGmSharedSnapshots = new List<String>();
    for(CS_Contract_Snapshot__Share share: newGmShares) {
        newGmSharedSnapshots.add(share.ParentId);
        system.debug('Share Parent ID List: '+newGmSharedSnapshots)
        system.assert(newGmSharedSnapshots.contains(share.ParentId))
    }

really strange - just looking for some ideas.

7
  • With just what you have, this code should not compile; share is outside the scope of the for loop it is defined in. Even so, this may a variation of a bug where this happens with ID values.
    – sfdcfox
    Dec 19, 2018 at 19:12
  • Does this even compile? You won't be able to access share outside the loop.
    – Jayant Das
    Dec 19, 2018 at 19:12
  • I made an edit to include the assertion in the loop - it does compile
    – Brohan
    Dec 19, 2018 at 19:16
  • Pretty sure this question is a duplicate but having trouble finding the original.
    – Adrian Larson
    Dec 19, 2018 at 19:17
  • 2
    This Known Issue might be it.
    – Adrian Larson
    Dec 19, 2018 at 19:20

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.