function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Yogesh Dighe.Yogesh Dighe. 

Any problem in the followigng APEX code??

public class StringArrayTest
{
    public void generateStringArray()
    {
        String[] colors = new List<String>{'red','green','blue'};
        for(Integer i=0;i<colors.size();i++)
         {
             // Write value to the debug log
              System.debug(colors[i]+i);
         }
    }
}


M just fresher in SFDC...
How can i run above code.??
Thanx in Advance :)
Best Answer chosen by Yogesh Dighe.
sanket supesanket supe
@Yogesh : Hi try this code.......first 

public class StringArrayTest {
        public static String[] generateStringArray(Integer length) {
        String[] myArray = new List<String>();
        for(Integer i=0;i<length;i++) {
           myArray.add('Test ' + i);

            System.debug(myArray[i]);
        } 
        return myArray;
    }     
}



And go :
Your Name>Developer Console>Debug>Open Execute Anonymous Window > Past it below code and click > Execute..

Integer lenght;
String[] myArray = new List<String>();
for (Integer i=0;i<lenght;i++){
    myArray.add('Test' + i);
System.debug(myArray[i]);
}
return myArray;



And see Log... And double click recent log....> Its Give u proper output... display Log...

 

All Answers

Zuinglio Lopes Ribeiro JúniorZuinglio Lopes Ribeiro Júnior
Hello,

It seems correct and if you just want to execute the code and see the result, you can use the developer console using execute anonymus. Execute just the following code:
String[] colors = new List<String>{'red','green','blue'};
        for(Integer i=0;i<colors.size();i++)
         {
             // Write value to the debug log
              System.debug(colors[i]+i);
         }

https://help.salesforce.com/apex/HTViewHelpDoc?id=code_dev_console_execute_anonymous.htm&language=en (https://help.salesforce.com/apex/HTViewHelpDoc?id=code_dev_console_execute_anonymous.htm&language=en" target="_blank)

Regards

Don't forget to mark your thread as 'SOLVED' with the answer that best helps you.
 
Shaijan ThomasShaijan Thomas
Call the class from developer console.
ie StringArrayTest ST = StringArrayTest ();
ST.generateStringArray();

Shaijan
 
Yogesh Dighe.Yogesh Dighe.
i was do that.. but it gives me 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."
Shaijan ThomasShaijan Thomas
public class StringArrayTest {
    public static String[] generateStringArray(Integer length) {
        String[] myArray = new List<String>();
        for(Integer i=0;i<length;i++) {
            myArray.add('Test ' + i);
        }
        return myArray;
    }      
}

for challenge try this code
Shaijan
Sagar PareekSagar Pareek
Your Name>Developer Console>Debug>Open Execute Anonymous Window 
Paste below code in it 
 
StringArrayTest ST = StringArrayTest ();
ST.generateStringArray();

Click Execute. 

 
Yogesh Dighe.Yogesh Dighe.
Now it gives me. "Method does not exist or incorrect signature: StringArrayTest()"
Shaijan ThomasShaijan Thomas
If you are doing challenge. replace entire code with the above code I put. Then click on recheck challeng
Shaijan
Anoop yadavAnoop yadav
Hi,
Try the below code on developer console.
StringArrayTest ST = new StringArrayTest();
ST.generateStringArray();
You are not using the new operator in the your code.
it will work now.
 
Yogesh Dighe.Yogesh Dighe.
Thank you so much all of you.. challenge is complete now :)
But still that code can't gives me proper output :(
sanket supesanket supe
@Yogesh : Hi try this code.......first 

public class StringArrayTest {
        public static String[] generateStringArray(Integer length) {
        String[] myArray = new List<String>();
        for(Integer i=0;i<length;i++) {
           myArray.add('Test ' + i);

            System.debug(myArray[i]);
        } 
        return myArray;
    }     
}



And go :
Your Name>Developer Console>Debug>Open Execute Anonymous Window > Past it below code and click > Execute..

Integer lenght;
String[] myArray = new List<String>();
for (Integer i=0;i<lenght;i++){
    myArray.add('Test' + i);
System.debug(myArray[i]);
}
return myArray;



And see Log... And double click recent log....> Its Give u proper output... display Log...

 
This was selected as the best answer
Shaijan ThomasShaijan Thomas
StringArrayTest ST = new StringArrayTest();
list<string> Mystrings = StringArrayTest.generateStringArray(100);
system.debug('************'+Mystrings);

//Try this code in developer console, it will work

Shaijan
sanket supesanket supe
@yogesh: Also Try below code it will work

StringArrayTest ST = new StringArrayTest();
list<string> myArray = StringArrayTest.generateStringArray(100);
system.debug('************'+myArray);