+ Start a Discussion
Saurabh SarpotdarSaurabh Sarpotdar 

Using Execute Anonymous Window to execute an apex class..!!

I have a very basic question. Through Force.com developer console I created a new apex class..say xyz.apxc then I wrote my code and saved my class..now I want to run that class using Developer console.. how I can do that..? Please tell me how can I use System.debug to  execute my class...What will be the steps..?
Ajay K DubediAjay K Dubedi
Hi Saurabh,
To execute your class follow the steps below:
1) Click Debug. | Open Execute Anonymous Window or CTRL+E.
2) In the Enter Apex Code window, call the method with the name of the class if method is static
3) Click Execute
User-added image

User-added image

If you want to see debug log then select Debug Only option
User-added image

vahidkhan lodhivahidkhan lodhi

I want execute List , so how can i do it??
smriti sharan19smriti sharan19
Hi Vahid Khan
List<string> l1= new List<string>();
system.debug('names' + l1);

This is how we create a list 
Here list strores string data type and add is method of list which stores values. We use system.debug to print value in debug log. Copy code in your org to see how it works

To read more about it check 
List in Apex (https://www.sfdcamplified.com/2018/11/list-methods-in-salesforce-with-interesting-examples.html)
smriti sharan19smriti sharan19
Hi Saurabh Sarpotdar, I have give explaination for your scanrio. I hope its clear. If you like my answer then mark it as best answer

Scenario - Create a new apex class with name apex, write code and save it. Run class in developer log.

User-added image

Code for class
public class Apex {

    public static void myName()
        system.debug('sfdc Amplified');

Code for anyonymous window

1. Go to Developer Console
2. Go to File -> New -> Apex Class -> Put class name as 'Apex'
3. Write the above code. This code has class name 'Apex' and method name 'myName'
4 It contains sytem.debug, which is used to print the value in debug log
5. Go to Debug -> Open Execute Anonymous Window
6. Paste the second code. It contains class. method name 
7. Click Execute
8. Click Debug log

User-added image

To understand more basics go to below link:
sfdc Amplified (https://www.sfdcamplified.com/)