Howdy! Welcome to Camp Apex.
Before we learn to code, let's learn how to write comments.
Comments are optional notes that live alongside your code. They can enrich your code by explaining what it does or why it was written a certain way.
In Apex, you create comments using the //
notation. This syntax tells Salesforce to disregard everything to the right of the //
. This type of comment is called an inline comment.
Comments do not impact your code; Salesforce ignores them during code execution. Here's an example of an inline comment that comments out an entire line:
// This is an in-line comment. You got this; you're building a solid foundation!
Since everything to the right of //
gets ignored, you can also make comments that sit on the same line as your code:
String greetings = 'Hello World'; // This part in green is the comment
In the above example, everything to the right of //
gets disregarded, and everything to the left gets treated as code. You'll see this throughout the course.
That's it! That's all you need to know about comments. Give the challenge below a try, and good luck in your developer journey! I'm rooting for you!