You need to sign in to do that
Don't have an account?

can't have statements like that directly inside a class. Please keep only field declarations inside class and all the other statements inside a method in class. Also the field intitalisations should be inside a constructor.
If I am writhing the code directly in side the class , getting errors like Right curly brace({) and unexpected token error . Same code when i am writing in side the method i did not get any Error , my code is working fine ,Could you please let me know what is the technical thing here...like oops concept , please i am new for the APEX coding , should not hesitate .
One of the first rules that you need to keep in mind in Apex is that in a class you can only declare variables, methods or inner classes, but you cannot create for instance a forloop directly in the class, it must be inside a method. In a similar way, if you declare an inner class, a forloop should be also inside of a method. This link (https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_qs_HelloWorld.htm) give you some guides about how to start.
Hope this helps