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
Newbie10Newbie10 

Class instantiation in anonymous block

I am running below code in anonymous block and i get some weird 'internl error'

cannot figure out why .I am new to apex.please help

public class abcd
{public void m1()
{
system.debug('hi');
}

}
abcd objec = new abcd();
objec.m1();

SForceBeWithYouSForceBeWithYou
It has been my experience that the times when you can define a class and not get an error are the following:
1) Anonymous block: Not at all (sorry)
2) Apex Class (like the thing starting with 01p):
a) You can obviously have the top level class... This is what determines the name of the Apex Class.
b) Inner class: You can have a class definition inside your Apex Class. You CANNOT, however, create yet another layer if class inside an inside class... only one layer of nesting.
3) Apex Trigger
a) Inner class: Since you are already in a sort of code container (a trigger), you can only make one level of classes within a trigger.

Not sure how many classes you can define within a trigger or class, but at that point, especially within a trigger (or an anonymous block if it WERE possible), I might ask myself why I don't make this its own Apex Class, or break several inner classes out into more topic specific Apex Classes with less inner classes each.