Skip to main content

I have run the test several times with pass status. I checked debug logs which prints the message ('Hello' & 'World') as expected. Seems like a glitch in the trailhead verification.  

 

Can someone for Salesforce support help? 

 

#Trailhead Challenges

4 answers
  1. Nov 23, 2025, 9:44 PM

    Hi Community, 

     

    The below test class helped me pass the challenge. Run this class from  

    Setup >Application Test Execution, select your test class (MyIterableTest) and run it.

     

     

    /**

     * @description Test class for MyIterable

     * Tests the custom Iterable implementation for String lists

     */

    @isTest

    private class MyIterableTest {

        

        /**

         * @description Test constructor and iterator with a valid list of strings

         */

        @isTest

        static void testIterableForLoop() {

            // Arrange

            List<String> strings = new List<String>{'Hello','World'};

            

            Test.startTest();

            

            // Act

            MyIterable myIterable = new MyIterable(strings );

            Iterator<String> iterator = myIterable.iterator();

            

            List<String> iteratedStrings = new List<String>();

            while (iterator.hasNext()) {

                iteratedStrings.add(iterator.next());

                

            }

            

            Test.stopTest();

            System.debug(iteratedStrings[0]);

            System.debug(iteratedStrings[1]);

            

            // Assert

            Assert.areEqual(2, iteratedStrings.size(), 'Should iterate over all 2 strings');

            Assert.areEqual('Hello', iteratedStrings[0], 'First element should be Hello');

            Assert.areEqual('World', iteratedStrings[1], 'Second element should be World');

        }

    }

0/9000