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
RedSalesRedSales 

Using System.debug('hello'); Gives "expecting a right parentheses" error?

Hello,

 

I'm new to Apex & in a clas I'm writing I want to print out debug statements at various steps however I can't seem to get these to work.

 

if I do

 

System.debug('hello');

 

I get an error as follows

 

Multiple markers at this line
 - expecting a right parentheses, found 'hello'
 - Save error: expecting a right parentheses,
  found 'hello'

 

Does anyone have any ideas as to why this may be occuring?  If I look at sample code online the above should work.

Best Answer chosen by Admin (Salesforce Developers) 
sebcossebcos

Hi,

I am assuming you are trying to call the method from outside a class method as in the code below:

public class systemdebug{
    // this is not possible outside a method - comment out
    system.debug('hello');
    
    public static void testdebug(){
        system.debug('hello');
    }
}

In this case I get the error message you mention above.

Classes work like Java or C# classes.

You could on the other hand get away with the system.debug without a method in a trigger because triggers are like scripts.

Please review the Apex Developer guide and in particular the section which explains Apex classes: 

http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_classes_understanding.htm

 

and the one which compares Apex to Java:

http://www.salesforce.com/us/developer/docs/apexcode/index_Left.htm#StartTopic=Content/apex_classes_java_diffs.htm?SearchType=Stem

 

and the one which explains triggers:

http://www.salesforce.com/us/developer/docs/apexcode/index_Left.htm#StartTopic=Content/apex_triggers.htm

 

 

 

 

 

All Answers

sebcossebcos

Hi,

I am assuming you are trying to call the method from outside a class method as in the code below:

public class systemdebug{
    // this is not possible outside a method - comment out
    system.debug('hello');
    
    public static void testdebug(){
        system.debug('hello');
    }
}

In this case I get the error message you mention above.

Classes work like Java or C# classes.

You could on the other hand get away with the system.debug without a method in a trigger because triggers are like scripts.

Please review the Apex Developer guide and in particular the section which explains Apex classes: 

http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_classes_understanding.htm

 

and the one which compares Apex to Java:

http://www.salesforce.com/us/developer/docs/apexcode/index_Left.htm#StartTopic=Content/apex_classes_java_diffs.htm?SearchType=Stem

 

and the one which explains triggers:

http://www.salesforce.com/us/developer/docs/apexcode/index_Left.htm#StartTopic=Content/apex_triggers.htm

 

 

 

 

 

This was selected as the best answer
RedSalesRedSales

Thanks for the help sebcos. Appreciated! 

Kharla HaldosKharla Haldos
Thanks to know this :)