• Ashwini ns 5
  • NEWBIE
  • 15 Points
  • Member since 2015

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 2
    Replies
If the code is correct but not accepting in trail head means its because of the space b/w Test and i .

try this code:

public class StringArrayTest {

    public static List<String> generateStringArray(integer lenght){
        
        List<String> st=new List<String>();
        For(integer i=0;i<lenght;i++)
        {
            st.add('Test'+ ' '+ i);   //check this part you need to provide space.
            system.debug(st[i]);
        }
        return st;
    }
}
Hello,

This is the trailhead questions which I am trying to solve :

Create an Apex class that returns an array (or list) of formatted strings ('Test 0', 'Test 1', ...). The length of the array is determined by an integer parameter.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 an array (or list) of strings. Each string must have a value in the format 'Test n' where n is the index of the current string in the array. The number of returned strings is specified by the integer parameter to the 'generateStringArray' method.


Here is my code :

public class StringArrayTest {
    public static List <String> generateStringArray (Integer n) {
       List<String> List1 = new List<String> ();
        for(Integer i=0;i<n;i++) {
          List1.add('\'Test'+ i+'\'' );
  }
        System.debug(List1);
        return List1;
    } 

}


I am getting following error :

Challenge not yet complete... here's what's wrong: 
Executing the 'generateStringArray' method failed. Either the method does not exist, is not static, or does not return the proper number of strings.


I tried it many times but I am not able to solve this problem. Please help. 



 
Hi All,

Below are the requirements to complete Challenge

The Account object will need a new custom checkbox that should have the Field Label 'Match Billing Address' and Field Name of 'Match_Billing_Address'. The resulting API Name should be 'Match_Billing_Address__c'.
With 'AccountAddressTrigger' active, if an Account has a Billing Postal Code and 'Match_Billing_Address__c' is true, the record should have the Shipping Postal Code set to match on insert or update.


I have created new custom Checkbox(MatchBillingAddress) and Below is my trigger:

trigger AccountAddressTrigger on Account (before update,before insert)
{
   List<Account> list1=[SELECT Id,Match_Billing_Address__c,ShippingPostalCode,BillingPostalCode from Account];
  for(Integer i=0;i<list1.size();i++)
   {
    if(list1[i].Match_Billing_Address__c=true && list1[i].BillingPostalCode!=NULL)
    {
    list1[i].ShippingPostalCode=list1[i].BillingPostalCode;
    update list1[i];
    }
   }
  }

I got Error like : Executing the trigger did not work as expected.

Can anyone please help me to achieve this. Thanks