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
PyramidPyramid 

Can an Apex statement use more than one line?

I have a few long lines of code that I need to wrap onto 2 lines rather than just using one line.  Is there a statement continuation character or something that will let me do that?

 

Thanks,

 

Doug

Best Answer chosen by Admin (Salesforce Developers) 
rungerrunger

Whitespace (including newlines) are generally ignored in Apex.  The following statements are all identical:

 

 

List<account> accs = [select id, name from account];

List<account>
  accs = [select id, name from account];

List<account> accs =
  [select id,
          name
   from
          account];

 

Rich

 

All Answers

paul-lmipaul-lmi

most types can.  for instance, string concatenation

 

string blah = 'testing' +

'some more testing';

 

AFAIK, there's no character to clue that in, it either works or doesn't.

rungerrunger

Whitespace (including newlines) are generally ignored in Apex.  The following statements are all identical:

 

 

List<account> accs = [select id, name from account];

List<account>
  accs = [select id, name from account];

List<account> accs =
  [select id,
          name
   from
          account];

 

Rich

 

This was selected as the best answer