트레일헤드/Hands-on Challenge

[Hands-on Challenge] Create an Apex class with a method that returns a list of strings

해연세포 2023. 2. 8. 19:32

https://trailhead.salesforce.com/content/learn/modules/apex_database/apex_database_intro

Hands-on Challenge

Create an Apex class with a method that returns a list of strings


Create an Apex class with a method that returns a list of formatted strings. The length of the list is determined by an integer parameter. You can also use an array if you prefer, but these instructions assume you’re using a list.

  • The Apex class must be called StringArrayTest and be in the public scope
  • The Apex class must have a public static method called generateStringArray
  • The generateStringArray method must return a list of strings

public with sharing class StringArrayTest {
        public static List<String> generateStringArray(Integer n){
            List<String> test = new List<String>();
            for(Integer i=0; i<n; i++){
                test.add('Test '+i);
                system.debug(test[i]);
            }
            return test;
        }
    }