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

Style question


    So I am new to apex and salesforce and I have been going through a lot of apex.  I know all you experienced devs just cringed a little lol, dont wory I am not modifying anything.  Anyway, the code I am looking at is very sloppy from a styling standpoint.  There appears to be no structured way that the coders have stuck to in order to make the code easily readible.  There is no consistant use of tabbing or even consistancy in the amount of whitespace between words or blocks.  So I have also see, and this is the point of the post, a lot of lines that run on and on. All the code in the first example is shown below EXCEPT it is all one line.  So in order to see it you would have to horizontally scroll quite a bit.    


BusinessHours bHr = [Select b.WednesdayStartTime, b.WednesdayEndTime, b.TuesdayStartTime, b.TuesdayEndTime, b.TimeZoneSidKey, b.ThursdayStartTime, b.ThursdayEndTime, b.SystemModstamp, b.SundayStartTime, b.SundayEndTime, b.SaturdayStartTime, b.SaturdayEndTime, b.Name, b.MondayStartTime, b.MondayEndTime, b.LastModifiedDate, b.LastModifiedById, b.IsDefault, b.IsActive, b.Id, b.FridayStartTime, b.FridayEndTime, b.CreatedDate, b.CreatedById From BusinessHours b WHERE b.IsDefault=true AND b.IsActive = true LIMIT 1];


My question is, can a newline be entered after the comma that separates the fields in the query? I do not have the ability to test it for myself so I wanted to turn to you guys for assistance.  

Best Answer chosen by Admin (Salesforce Developers) 

Yes.. no problems.

All Answers


Yes.. no problems.

This was selected as the best answer

In this particular query, the 'b.' notation provides no additional documentation value; 


I also tend to order my fields alphabetically when there are long lists of fields as in 


[Select id, a__c,b__c,c__c,d__c,e__c,f__c,
   from Foo__c 
   where <some condition>];



Thanks for the replies guys.


The aliasing is automatically added to the query if it is built in the IDE.  I was also curious why it was used, then went into the ide and built a few queries and noticed it automatically does it.  

shraddha kawaneshraddha kawane
yes, a newline be entered after the comma that separates the fields in the query