Salesforce

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

송테이토 2023. 2. 10. 10:28

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;
        }
    }