+ 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