You need to sign in to do that
Don't have an account?
Arav Sundar
unexpected token error
HI All ,
learning SFDC coding , need a help please .. in the Apex guide i am trying to execute the below code in the anonymus block in the developer console when i click on execute i am getting an error unexpected token at line 2 .. But if i save the same code directly in the apex class no error its getting saved , can anyone tell me how is it working .. And i am getting an error in the system.debug line where i am using as red cant i put the debug statement there pls confirm
public class MyClass {
class RGB {
Integer red;
system.debug (this is red : + red);
Integer green;
Integer blue;
//Static and Instance Methods, Variables, and Initialization Code
//Classes, Objects, and Interfaces
RGB(Integer red, Integer green, Integer blue)
system.debug(this is RGB : + RGB);
{ this.red = red;
this.green = green;
this.blue = blue; }
}
static Map<String, RGB> colorMap = new Map<String, RGB>();
system.debug(this is the static colormap : + colorMap);
static {
colorMap.put('red', new RGB(255, 0, 0));
colorMap.put('cyan', new RGB(0, 255, 255));
colorMap.put('magenta', new RGB(255, 0, 255)); }
}
learning SFDC coding , need a help please .. in the Apex guide i am trying to execute the below code in the anonymus block in the developer console when i click on execute i am getting an error unexpected token at line 2 .. But if i save the same code directly in the apex class no error its getting saved , can anyone tell me how is it working .. And i am getting an error in the system.debug line where i am using as red cant i put the debug statement there pls confirm
public class MyClass {
class RGB {
Integer red;
system.debug (this is red : + red);
Integer green;
Integer blue;
//Static and Instance Methods, Variables, and Initialization Code
//Classes, Objects, and Interfaces
RGB(Integer red, Integer green, Integer blue)
system.debug(this is RGB : + RGB);
{ this.red = red;
this.green = green;
this.blue = blue; }
}
static Map<String, RGB> colorMap = new Map<String, RGB>();
system.debug(this is the static colormap : + colorMap);
static {
colorMap.put('red', new RGB(255, 0, 0));
colorMap.put('cyan', new RGB(0, 255, 255));
colorMap.put('magenta', new RGB(255, 0, 255)); }
}
Just update you class same like below class.
Please follow below step :-
Step 1) Click on Your Name then click on Developer console.
Step 2) In developer console click on Debug and open Anonymous window like below or click
Step 3) Enter below code in Anonymous window like below
MyClass obj = new MyClass();
Step 4) Click on Open log check box and click on execute like above screen shot.
Step 5) Then search your debug like below "this is the static colormap"
I tested above code in my developer org which is working fine. Please let us know if this will help you
Thanks
Amit Chaudhary
amit.salesforce21@gmail.com
All Answers
Please check the below modified code:
The above class is saving it properly. But I would recommend to follow below links to learn about Apex Programming.
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_intro_what_is_apex.htm
https://developer.salesforce.com/page/Apex
https://developer.salesforce.com/page/An_Introduction_to_Apex
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_intro_learning_apex.htm
https://resources.docs.salesforce.com/sfdc/pdf/salesforce_apex_language_reference.pdf
Please do let me know if it helps you.
Regards,
Mahesh
1) Debug system outside the constructor and method
2) No ' ' in Debug Statement
Please update your class like below
To excute above class try below code on developer console Output will :-
Let us know if this will help you
@ Mahesh - its saving proprely in the Apex class but if you execute the same in the developer console you will get an error
@ Amit - R u telling to execute this in the Developer console if yes this is not happening and if you saving this in the Apex class how are you executing this code can you pls tell me that
First save this class in Salesforce UI:
Go to Developer Console and create an object for the parent class:
MyClass mc = new MyClass();
This way it will work properly. Also don't forget to enable the debug so that it will be easy for you to see the output.
Regards,
Mahesh
Just update you class same like below class.
Please follow below step :-
Step 1) Click on Your Name then click on Developer console.
Step 2) In developer console click on Debug and open Anonymous window like below or click
Step 3) Enter below code in Anonymous window like below
MyClass obj = new MyClass();
Step 4) Click on Open log check box and click on execute like above screen shot.
Step 5) Then search your debug like below "this is the static colormap"
I tested above code in my developer org which is working fine. Please let us know if this will help you
Thanks
Amit Chaudhary
amit.salesforce21@gmail.com