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
SuAkSuAk 

How to execute insert in Anonymous window in Apex

Hi - I am trying to execute the following code

public class AccountHandler {
public static Account insertNewAccount(String name) {
Account a = new Account();
a.Name = name;
try
{
insert a;
} catch (Exception e) {
return null;
}
return a;
}
}

i tried executing it in anonymous window as below :

AccountHandler.Account insertNewAccount(String name);

I would need some help on this . Please let me know if the way i execute in anonymous window is correct .

Thanks!!
Best Answer chosen by SuAk
@Karanraj@Karanraj
In the Execute anonymous window, you need to call the method with the string value which you want to pass
AccountHandler.insertNewAccount("Treailhead");
Now it will insert the account with the Name as Trailhead in your org. To understand about class and method check the trailhead module - https://developer.salesforce.com/trailhead/modules
 

All Answers

Dan1126Dan1126
It should be like this

AccountHandler.insertNewAccount("your string here");
@Karanraj@Karanraj
In the Execute anonymous window, you need to call the method with the string value which you want to pass
AccountHandler.insertNewAccount("Treailhead");
Now it will insert the account with the Name as Trailhead in your org. To understand about class and method check the trailhead module - https://developer.salesforce.com/trailhead/modules
 
This was selected as the best answer
Simran RawatSimran Rawat
mine wasn't executing first with the string in double qoutes so i replaced the double quotes with the single quotes and it's done...

AccountHandler.insertNewAccount('your string here');