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
Savi3Savi3 

Error while using System.debug

Hi,

 

    I'm getting "Compile Error: unexpected token: ')' at line 19 column 22"  while using System.debug.

I need to get the email of the logged in user. For that i wrote this code:

ID usrid = UserInfo.getUserId();

List<User> cusr = [Select Email From User where id =: usrid ];

String uEmail = cusr[0].Email;
System.debug(uEmail); ---------------------- (Line 19)

 

Can somebody tell me why this is happening and its solution? Please..

 

Thank you,

Savi3.


Best Answer chosen by Admin (Salesforce Developers) 
Savi3Savi3

  I got its answer....

We can use debug statements only in methods of a class...

 

 

public constructorforClass()
   {
    cusr = [Select Email From User  where id =: usrid Limit 1];
    uEmail = cusr.Email;
     contmap = new Map<id,contact>([Select id,name from contact where EmailAddress__c = :uEmail]);
    
    
    System.debug(uEmail); 
   }

Thank you,

Sav3

All Answers

Andy WiddessAndy Widdess

As a newbie, I have been looking at the discussion boards and come across your post.

 

As the code stands, it compiles successfully with v24.

This may suggest the compiler error is being reported from another error in your class.

 

Using your example code.

I've added a controller wrapper and static method to allow me to call your code from the console

 

public class TestController
{
    public static void LogMsg()
    {
        ID usrid = UserInfo.getUserId();
        List<User> cusr = [Select Email From User where id =: usrid ];
        String uEmail = cusr[0].Email;
        System.debug(uEmail);
    }
}

 

Using the console to execute the method:

 

TestController.LogMsg();

 

The raw log shows the call to LogMsg and the logging of your email address using the default DEBUG log type:

 

24.0 APEX_CODE,FINEST;APEX_PROFILING,INFO;CALLOUT,INFO;DB,INFO;SYSTEM,DEBUG;VALIDATION,INFO;VISUALFORCE,INFO;WORKFLOW,INFO
Execute Anonymous: TestController.LogMsg();
21:39:17.044 (44822000)|EXECUTION_STARTED
21:39:17.044 (44836000)|CODE_UNIT_STARTED|[EXTERNAL]|execute_anonymous_apex
21:39:17.045 (45466000)|STATEMENT_EXECUTE|[1]
21:39:17.045 (45476000)|STATEMENT_EXECUTE|[1]
21:39:17.047 (47673000)|METHOD_ENTRY|[1]|01pD000000121tg|TestController.TestController()
21:39:17.047 (47685000)|STATEMENT_EXECUTE|[1]
21:39:17.047 (47823000)|SYSTEM_MODE_ENTER|false
21:39:17.047 (47848000)|HEAP_ALLOCATE|[1]|Bytes:5
21:39:17.047 (47858000)|STATEMENT_EXECUTE|[1]
21:39:17.047 (47868000)|SYSTEM_MODE_EXIT|false
21:39:17.047 (47880000)|METHOD_EXIT|[1]|TestController
21:39:17.047 (47910000)|METHOD_ENTRY|[1]|01pD000000121tg|TestController.LogMsg()
21:39:17.047 (47960000)|SYSTEM_MODE_ENTER|false
21:39:17.047 (47970000)|HEAP_ALLOCATE|[5]|Bytes:5
21:39:17.047 (47976000)|STATEMENT_EXECUTE|[4]
21:39:17.047 (47980000)|STATEMENT_EXECUTE|[5]
21:39:17.048 (48048000)|SYSTEM_METHOD_ENTRY|[5]|system.UserInfo.getUserId()
21:39:17.048 (48136000)|SYSTEM_METHOD_EXIT|[5]|system.UserInfo.getUserId()
21:39:17.048 (48167000)|HEAP_ALLOCATE|[5]|Bytes:18
21:39:17.048 (48182000)|VARIABLE_SCOPE_BEGIN|[5]|usrid|Id|false|false
21:39:17.048 (48203000)|VARIABLE_ASSIGNMENT|[5]|usrid|"005D0000001zdPhIAI"
21:39:17.048 (48209000)|STATEMENT_EXECUTE|[6]
21:39:17.048 (48219000)|HEAP_ALLOCATE|[6]|Bytes:42
21:39:17.048 (48241000)|HEAP_ALLOCATE|[6]|Bytes:7
21:39:17.048 (48280000)|HEAP_ALLOCATE|[6]|Bytes:-4
21:39:17.048 (48516000)|SOQL_EXECUTE_BEGIN|[6]|Aggregations:0|select Email from User where id = :tmpVar1
21:39:17.053 (53818000)|SOQL_EXECUTE_END|[6]|Rows:1
21:39:17.053 (53837000)|HEAP_ALLOCATE|[6]|Bytes:8
21:39:17.053 (53852000)|HEAP_ALLOCATE|[6]|Bytes:73
21:39:17.053 (53961000)|HEAP_ALLOCATE|[6]|Bytes:77
21:39:17.053 (53984000)|VARIABLE_SCOPE_BEGIN|[6]|cusr|LIST|true|false
21:39:17.054 (54019000)|VARIABLE_ASSIGNMENT|[6]|cusr|[{"Email":"<<myemailaddress>>.","Id":"005D0000001zdPhIAI"}]|0x2811889f
21:39:17.054 (54028000)|STATEMENT_EXECUTE|[7]
21:39:17.054 (54116000)|VARIABLE_SCOPE_BEGIN|[7]|uEmail|String|false|false
21:39:17.054 (54132000)|VARIABLE_ASSIGNMENT|[7]|uEmail|"<<myemailaddress>>"
21:39:17.054 (54139000)|STATEMENT_EXECUTE|[8]
21:39:17.054 (54161000)|SYSTEM_METHOD_ENTRY|[8]|System.debug(ANY)
21:39:17.054 (54202000)|USER_DEBUG|[8]|DEBUG|<<myemailaddress>>
21:39:17.054 (54213000)|SYSTEM_METHOD_EXIT|[8]|System.debug(ANY)
21:39:17.054 (54224000)|SYSTEM_MODE_EXIT|false
21:39:17.054 (54235000)|METHOD_EXIT|[1]|01pD000000121tg|TestController.LogMsg()
21:39:17.621 (54272000)|CUMULATIVE_LIMIT_USAGE
 

 

Savi3Savi3

  I got its answer....

We can't use debug statements only in methods of a class...

 

Savi3Savi3

  I got its answer....

We can use debug statements only in methods of a class...

 

 

public constructorforClass()
   {
    cusr = [Select Email From User  where id =: usrid Limit 1];
    uEmail = cusr.Email;
     contmap = new Map<id,contact>([Select id,name from contact where EmailAddress__c = :uEmail]);
    
    
    System.debug(uEmail); 
   }

Thank you,

Sav3

This was selected as the best answer