Hello. This is my first question, so I apologize for any confusion.
In order to update my Salesforce Certified Platform Developer qualification, I created the following code.
MyIterable.cls
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();
}
}
MyIterableTest.cls
@isTest
public class MyIterableTest {
@isTest
public static void testIterableForLoop() {
Test.startTest();
List<String> strings = new List<String>{'hello', 'World'};
MyIterable myIterable = new MyIterable(strings);
for (String str : myIterable) {
System.debug(str);
}
Test.stopTest();
}
}
The deployment was successful, and the test ran as expected, with debug logs appearing correctly.
However, I cannot resolve the following error in the Challenge:
"Challenge is not yet complete in the Cunning Panda Playground."
The error message states:
"The testIterableForLoop method does not have the @IsTest annotation."
I have confirmed that the organization and language settings are both set to English.
I have also checked the website, but I was unable to resolve the issue.
I would appreciate any guidance in resolving this.
Thank you very much!
Hi, @智喜 宮下
Try to use this code:
Apex Code:
public class MyIterable implements Iterable<String> {
Private List<String> strings;
// Constructor to initilize the list of strings
public MyIterable(List<String> strings)
{
this.strings = strings;
}
// Implementing the iterator method
public Iterator<String> iterator(){
return strings.iterator();
}
}
Test Class:
@IsTest
public class MyIterableTest {
@IsTest
static void testIterableForLoop(){
// Create a list of strings
List<String> strings = new List<String> {'Hello', 'World'};
// Create an Instance of MyIterable
MyIterable myIterable = new MyIterable(strings);
// Use a for loop to iterate over the MyIterable instance
for(String str: myIterable)
{
//Print each string to the debug log
System.debug(str);
}
}
}
Sincerely,
Mykhailo Vdovychenko
Bringing Cloud Excellence with IBVCLOUD OÜ