Skip to main content Join us at TDX in San Francisco or on Salesforce+ on March 5-6 for the Developer Conference for the AI Agent Era. Register now.

Getting issue in validating the hands on challenge with the below error: The constructor MyIterable should accept parameter of type List<String>.

 

Here's my code snippet:

public class MyIterable implements Iterable<String>{    private List<String> strings;    public MyIterable(List<String> strings){        this.strings= strings;    }    public Iterator<String> iterator() {      return strings.iterator();   }}

 

#Trailhead Challenges

9 answers
  1. Jan 22, 1:22 PM

    I spent half a day trying to figure out why this error appears. The cause of the problem is very simple, a space between the method name and the opening bracket  

    I spent half a day trying to figure out why this error appears.

     

     

  2. Jan 4, 5:07 PM

    Try the suggestion above, to have a space on the assignment

    this.strings = strings;

  3. Feb 16, 9:53 AM

    There are a few other issues with the way the challenge gets parsed which cause the challenge to get failed, without being relevant to the result. 

    1. Defining the Myiterable constructor with an input parameter which is not literally named "strings". 

    2. Having brackets round the strings.iterator() return value in the Iterator method 

    3. In the test class, instantiating the MyIterable class within the for loop instead of a separate variable. 

    For 3. though, the release notes article for this feature uses exactly that for loop sysntax: 

     

    for (String str : new MyIterable()) {

    System.debug(str);

    }

  4. Jan 6, 11:11 AM

    i'm also facing this issue, test is working fine...

  5. Dec 13, 2024, 1:28 PM

    Make this one as @TestVisible 

     

        private List<String> strings;

    and it works.

0/9000