{"id":1216,"date":"2026-09-02T19:00:00","date_gmt":"2026-09-02T13:30:00","guid":{"rendered":"https:\/\/swapnilzambare.com\/blog\/apex-operators-expressions\/"},"modified":"2026-09-02T19:00:00","modified_gmt":"2026-09-02T13:30:00","slug":"apex-operators-expressions","status":"publish","type":"post","link":"https:\/\/swapnilzambare.com\/blog\/apex-operators-expressions\/","title":{"rendered":"Apex Operators and Expressions with Simple Examples"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Apex Operators are the symbols that let your code add numbers, compare values and combine conditions. Without them, variables would just sit there holding data. With them, you can work out a fee, check a date or decide whether a course is full.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In the previous post, you learned <a href=\"https:\/\/swapnilzambare.com\/blog\/apex-data-types-variables-constants\/\">Apex data types, variables and constants<\/a>. Now we will use operators to work with those values. If you need a refresher on running code, see our <a href=\"https:\/\/swapnilzambare.com\/blog\/salesforce-developer-console-guide\/\">Developer Console guide<\/a>. Every example here runs in anonymous Apex.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">What Are Apex Operators?<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">An operator is a symbol that performs an action on one or more values. We call the values operands. For example, in <code>fee + tax<\/code>, the <code>+<\/code> is the operator, and <code>fee<\/code> and <code>tax<\/code> are the operands.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">An expression is any piece of code that produces a value. So <code>fee + tax<\/code> is an expression, and so is <code>seats &gt; 30<\/code>. You can then store the result in a variable or use it in a decision.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Think of operators as the buttons on a calculator. The numbers are your data, and the buttons tell the calculator what to do with them. Apex just has a few more buttons than a normal calculator.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Why Apex Operators Matter<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Almost every line of real business logic uses Apex Operators. Here are a few things Bright Path Tutors needs every day.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Work out a fee after a discount, using arithmetic.<\/li>\n\n<li>Check whether a course has seats left, using comparison.<\/li>\n\n<li>Decide if a course is both online and cheap, using logical operators.<\/li>\n\n<li>Count students one by one, using increment.<\/li>\n\n<li>Avoid errors when a field is empty, using null-safe operators.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">So once you know Apex Operators, you can turn business rules into working code.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">How Apex Operators Work<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Apex reads an expression and applies each operator in a fixed order. Then it returns one final value. Developers call this order precedence. For example, multiplication runs before addition, just like in school maths.<\/p>\n\n\n\n<figure class=\"wp-block-image aligncenter size-large\"><a href=\"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/10\/apex-operators-expressions-diagram-1.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"640\" src=\"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/10\/apex-operators-expressions-diagram-1-1024x640.png\" alt=\"Apex Operators diagram showing six groups of operators with examples\" class=\"wp-image-1214\" srcset=\"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/10\/apex-operators-expressions-diagram-1-1024x640.png 1024w, https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/10\/apex-operators-expressions-diagram-1-300x188.png 300w, https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/10\/apex-operators-expressions-diagram-1-768x480.png 768w, https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/10\/apex-operators-expressions-diagram-1-1536x960.png 1536w, https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/10\/apex-operators-expressions-diagram-1-2048x1280.png 2048w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><figcaption class=\"wp-element-caption\">The main groups of Apex operators with an example of each.<\/figcaption><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">So <code>100 + 20 * 2<\/code> gives 140, not 240. If you want the addition first, use brackets, such as <code>(100 + 20) * 2<\/code>, which gives 240. Brackets always win, and they also make code easier to read.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Types of Apex Operators<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Apex groups Apex Operators into a few families, and each family has a clear job. The table below shows the main ones with a quick example of each.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Group<\/th><th>Operators<\/th><th>Example<\/th><\/tr><\/thead><tbody><tr><td>Arithmetic<\/td><td>+ &#8211; * \/<\/td><td>fee * 2<\/td><\/tr><tr><td>Assignment<\/td><td>= += -= *= \/=<\/td><td>total += fee<\/td><\/tr><tr><td>Increment and decrement<\/td><td>++ &#8212;<\/td><td>count++<\/td><\/tr><tr><td>Comparison<\/td><td>== != &lt; &gt; &lt;= &gt;=<\/td><td>seats &gt;= 30<\/td><\/tr><tr><td>Logical<\/td><td>&amp;&amp; or !<\/td><td>isOnline &amp;&amp; feeOk<\/td><\/tr><tr><td>Ternary<\/td><td>? :<\/td><td>isOnline ? &#8216;Online&#8217; : &#8216;Classroom&#8217;<\/td><\/tr><tr><td>Null-safe<\/td><td>?. ??<\/td><td>c?.Fee__c ?? 0<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">In the table, &#8220;or&#8221; stands for the double pipe symbol <code>||<\/code>, which means logical OR.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Arithmetic Operators<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">These do basic maths: <code>+<\/code> adds, <code>-<\/code> subtracts, <code>*<\/code> multiplies and <code>\/<\/code> divides. The <code>+<\/code> sign also joins strings, such as <code>'Hi ' + name<\/code>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Apex has no <code>%<\/code> operator for remainders. Instead, use <code>Math.mod(10, 3)<\/code>, which returns 1. Many people coming from Java or JavaScript miss this.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Integer Division<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">When you divide two Integers, Apex drops the decimal part. So <code>7 \/ 2<\/code> gives 3, not 3.5. To keep the decimal, make one side a <code>Decimal<\/code>, such as <code>7.0 \/ 2<\/code>, which gives 3.5. Also, dividing by zero throws a MathException, so check the divisor first.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Assignment Operators<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">The <code>=<\/code> sign stores a value in a variable. The short forms combine maths and assignment. For example, <code>total += fee;<\/code> means the same as <code>total = total + fee;<\/code>.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Increment and Decrement<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\"><code>count++<\/code> adds 1 to <code>count<\/code>, and <code>count--<\/code> takes 1 away. You will use these a lot inside loops.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Comparison Operators<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">These compare two values and return a Boolean. <code>==<\/code> means equal, <code>!=<\/code> means not equal, and the others check greater or less than.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Here is a surprise for many beginners. When you compare Strings with <code>==<\/code>, Apex ignores case. So <code>'apex' == 'APEX'<\/code> is <code>true<\/code>. If case matters, use <code>'apex'.equals('APEX')<\/code>, which returns <code>false<\/code>.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Logical Operators<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">The <code>&amp;&amp;<\/code> operator means AND, so both sides must be true. Next, <code>||<\/code> means OR, so at least one side must be true. Finally, <code>!<\/code> means NOT, and it flips true to false.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Apex also short-circuits. With <code>&amp;&amp;<\/code>, if the left side is false, Apex skips the right side. This is handy for safety, such as <code>c != null &amp;&amp; c.Fee__c &gt; 500<\/code>.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">The Ternary Operator<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">The ternary operator is a short <code>if-else<\/code> in one line. It has three parts: a condition, a value if true and a value if false.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Safe Navigation and Null Coalescing<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">The <code>?.<\/code> operator stops a NullPointerException. If the left side is null, the whole expression returns null. The <code>??<\/code> operator gives a fallback when a value is null. Together, they replace many long null checks.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">A Real Apex Operators Example<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Let&#8217;s build a fee calculator for Bright Path Tutors with Apex Operators. Online courses get a 10% discount, and students pay an 18% tax on the final amount. We also want a label for the course mode.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Decimal baseFee = 6000;\nBoolean isOnline = true;\nInteger seatsBooked = 28;\nInteger maxSeats = 30;\n\n\/\/ Arithmetic and ternary\nDecimal discount = isOnline ? baseFee * 10 \/ 100 : 0;\nDecimal feeAfterDiscount = baseFee - discount;\nDecimal tax = feeAfterDiscount * 18 \/ 100;\nDecimal finalFee = feeAfterDiscount + tax;\n\n\/\/ Comparison and logical\nBoolean almostFull = seatsBooked &gt;= maxSeats - 2;\nBoolean showWarning = almostFull &amp;&amp; isOnline;\n\nString mode = isOnline ? 'Online' : 'Classroom';\nSystem.debug(mode + ' fee: ' + finalFee);\nSystem.debug('Show warning: ' + showWarning);<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The ternary line sets <code>discount<\/code> to 600 for online courses and 0 for classroom ones. Then the next lines subtract the discount and add 18% tax. The comparison checks if only 2 or fewer seats remain. Finally, <code>&amp;&amp;<\/code> joins two conditions into one Boolean. Here is the log output.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>USER_DEBUG [17]|DEBUG|Online fee: 6372.00\nUSER_DEBUG [18]|DEBUG|Show warning: true<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Handling Empty Fields with Apex Operators<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Real records often have empty fields. Here, a course has no fee yet, and the code must not crash.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Course__c c = new Course__c(Name = 'Git Basics');\n\n\/\/ Without a check, c.Fee__c * 2 would throw an error\nDecimal fee = c.Fee__c ?? 0;\nInteger weeks = (c.Duration_in_Weeks__c ?? 4).intValue();\n\nCourse__c missing = null;\nString name = missing?.Name;\n\nSystem.debug('Fee: ' + fee + ', weeks: ' + weeks + ', name: ' + name);<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The <code>??<\/code> operator gives 0 when the fee is empty, and 4 when the duration is empty. Then <code>intValue()<\/code> turns the Decimal duration into an Integer. The <code>?.<\/code> line returns null instead of failing on a null record. So the log shows <code>Fee: 0, weeks: 4, name: null<\/code>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">== vs equals() for Strings<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">This is one of the most common interview questions on Apex Operators. The table below compares the two ways to check text.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Feature<\/th><th>== operator<\/th><th>equals() method<\/th><\/tr><\/thead><tbody><tr><td>Case sensitive<\/td><td>No<\/td><td>Yes<\/td><\/tr><tr><td>&#8216;Apex&#8217; vs &#8216;APEX&#8217;<\/td><td>true<\/td><td>false<\/td><\/tr><tr><td>Safe when left side is null<\/td><td>Yes<\/td><td>No, throws an error<\/td><\/tr><tr><td>Works for numbers too<\/td><td>Yes<\/td><td>Yes, through the object<\/td><\/tr><tr><td>Typical use<\/td><td>Most text checks<\/td><td>Exact matches, such as codes<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">When to use which depends on case. Use <code>==<\/code> for normal text checks, and <code>equals()<\/code> when uppercase and lowercase must match exactly.<\/p>\n\n\n\n<figure class=\"wp-block-image aligncenter size-large\"><a href=\"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/10\/apex-operators-expressions-diagram-2.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"640\" src=\"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/10\/apex-operators-expressions-diagram-2-1024x640.png\" alt=\"Apex Operators diagram comparing == and equals() for text\" class=\"wp-image-1215\" srcset=\"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/10\/apex-operators-expressions-diagram-2-1024x640.png 1024w, https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/10\/apex-operators-expressions-diagram-2-300x188.png 300w, https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/10\/apex-operators-expressions-diagram-2-768x480.png 768w, https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/10\/apex-operators-expressions-diagram-2-1536x960.png 1536w, https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/10\/apex-operators-expressions-diagram-2-2048x1280.png 2048w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><figcaption class=\"wp-element-caption\">The == operator vs the equals() method for Strings.<\/figcaption><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Operator Precedence Cheat Sheet<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">When an expression mixes many operators, Apex follows a set order. Here is a simple version, from first to last.<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Brackets <code>( )<\/code>.<\/li>\n\n<li>Increment, decrement and NOT, such as <code>++<\/code> and <code>!<\/code>.<\/li>\n\n<li>Multiply and divide, <code>*<\/code> and <code>\/<\/code>.<\/li>\n\n<li>Add and subtract, <code>+<\/code> and <code>-<\/code>.<\/li>\n\n<li>Comparisons, such as <code>&lt;<\/code> and <code>&gt;=<\/code>.<\/li>\n\n<li>Equality, <code>==<\/code> and <code>!=<\/code>.<\/li>\n\n<li>Logical AND <code>&amp;&amp;<\/code>, then logical OR.<\/li>\n\n<li>Ternary, then assignment, such as <code>=<\/code> and <code>+=<\/code>.<\/li>\n<\/ol>\n\n\n\n<p class=\"wp-block-paragraph\">You do not need to memorise this list. Instead, add brackets whenever an expression looks unclear. Your teammates will thank you.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Joining Text with Apex Operators<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">The <code>+<\/code> operator does double duty in Apex. With numbers, it adds. With Strings, it joins text together. If one side is a String, Apex turns the other side into text first.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">So <code>'Seats: ' + 30<\/code> gives <code>'Seats: 30'<\/code>. However, watch the order. <code>'Total: ' + 10 + 5<\/code> gives <code>'Total: 105'<\/code>, because Apex joins from left to right. To add first, use brackets, such as <code>'Total: ' + (10 + 5)<\/code>, which gives <code>'Total: 15'<\/code>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">For long messages, <code>String.format<\/code> is often cleaner than many plus signs. We will cover it in the post on built-in methods.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Apex Operators in Everyday Code<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">You will meet the same few patterns again and again. Learning them now makes later topics, such as triggers and loops, much easier.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">First, counters use <code>++<\/code>, such as <code>enrolled++<\/code> for every student who joins. Next, totals use <code>+=<\/code>, such as <code>totalFees += c.Fee__c<\/code>. Then guards use <code>&amp;&amp;<\/code> with a null check on the left, such as <code>c != null &amp;&amp; c.Is_Online__c<\/code>. Finally, labels use the ternary, such as <code>fee &gt; 8000 ? 'Premium' : 'Standard'<\/code>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">These four patterns cover most of the Apex Operators you will write in your first year. So practise them until they feel natural.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Common Mistakes with Apex Operators<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Using <code>%<\/code> for remainders. Apex does not support it, so use <code>Math.mod()<\/code>.<\/li>\n\n<li>Forgetting Integer division. <code>7 \/ 2<\/code> gives 3, so use a Decimal when you need 3.5.<\/li>\n\n<li>Expecting <code>==<\/code> to be case sensitive for Strings. It is not, so use <code>equals()<\/code> for exact matches.<\/li>\n\n<li>Doing maths on null fields. Use <code>??<\/code> or an <code>if<\/code> check first.<\/li>\n\n<li>Writing long expressions with no brackets. They are hard to read and easy to get wrong.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Best Practices for Apex Operators<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Use brackets to show your intent, even when precedence would work anyway.<\/li>\n\n<li>Use <code>Decimal<\/code> for money maths, so results stay exact.<\/li>\n\n<li>Put the null check on the left of <code>&amp;&amp;<\/code>, so short-circuiting protects you.<\/li>\n\n<li>Keep ternary expressions short. If one gets long, use a normal <code>if<\/code> statement.<\/li>\n\n<li>Use <code>??<\/code> for safe defaults, so empty fields never break your code.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Practice Task<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Write anonymous Apex that takes 47 students and puts them into batches of 10. Print how many full batches you get. Then print how many students remain. Hint: use <code>\/<\/code> with Integers for full batches and <code>Math.mod(47, 10)<\/code> for the rest.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Official Resources<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/developer.salesforce.com\/docs\/atlas.en-us.apexcode.meta\/apexcode\/langCon_apex_expressions_operators_understanding.htm\" target=\"_blank\" rel=\"noopener noreferrer\">Apex Developer Guide: Expression Operators<\/a><\/li>\n\n<li><a href=\"https:\/\/developer.salesforce.com\/docs\/atlas.en-us.apexcode.meta\/apexcode\/langCon_apex_SafeNavigationOperator.htm\" target=\"_blank\" rel=\"noopener noreferrer\">Apex Developer Guide: Safe Navigation Operator<\/a><\/li>\n\n<li><a href=\"https:\/\/trailhead.salesforce.com\/content\/learn\/modules\/apex_database\" target=\"_blank\" rel=\"noopener noreferrer\">Trailhead: Apex Basics and Database<\/a><\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Quick Recap<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Apex Operators let you calculate, compare and combine values.<\/li>\n\n<li>Apex has no <code>%<\/code> operator, so use <code>Math.mod()<\/code> for remainders.<\/li>\n\n<li>Dividing two Integers drops the decimal part.<\/li>\n\n<li><code>==<\/code> ignores case for Strings, while <code>equals()<\/code> does not.<\/li>\n\n<li><code>?.<\/code> and <code>??<\/code> keep your code safe when values are null.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">What&#8217;s Next?<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Operators give you true or false answers. Next, we use those answers to make decisions in <a href=\"https:\/\/swapnilzambare.com\/blog\/apex-conditional-statements-if-switch\/\">Apex conditional statements with if, else and switch<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Apex Operators are the symbols that let your code add numbers, compare values and combine conditions. Without them, variables would just sit there holding&hellip;<\/p>\n","protected":false},"author":1,"featured_media":1213,"comment_status":"","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"_swapz_level":"","_swapz_series_part":0,"_swapz_hide_toc":false,"_swapz_hide_featured":false,"_swapz_description":"","footnotes":""},"categories":[8,96],"tags":[98,15,7,97],"swapz_series":[],"class_list":["post-1216","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-salesforce","category-salesforce-developer","tag-apex","tag-beginner","tag-salesforce","tag-salesforce-developer"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v28.7 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Apex Operators and Expressions with Examples<\/title>\n<meta name=\"description\" content=\"Apex Operators explained with simple examples: arithmetic, comparison, logical, assignment, ternary, safe navigation and null coalescing.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/swapnilzambare.com\/blog\/apex-operators-expressions\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Apex Operators and Expressions with Examples\" \/>\n<meta property=\"og:description\" content=\"Apex Operators explained with simple examples: arithmetic, comparison, logical, assignment, ternary, safe navigation and null coalescing.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/swapnilzambare.com\/blog\/apex-operators-expressions\/\" \/>\n<meta property=\"og:site_name\" content=\"Swapnil Zambare - Blog\" \/>\n<meta property=\"article:published_time\" content=\"2026-09-02T13:30:00+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/10\/apex-operators-expressions-featured.png\" \/>\n\t<meta property=\"og:image:width\" content=\"2400\" \/>\n\t<meta property=\"og:image:height\" content=\"1260\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Swapnil Zambare\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Swapnil Zambare\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"8 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/apex-operators-expressions\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/apex-operators-expressions\\\/\"},\"author\":{\"name\":\"Swapnil Zambare\",\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/#\\\/schema\\\/person\\\/922ac0131aaa7088c78c2cb1700e0c9a\"},\"headline\":\"Apex Operators and Expressions with Simple Examples\",\"datePublished\":\"2026-09-02T13:30:00+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/apex-operators-expressions\\\/\"},\"wordCount\":1458,\"publisher\":{\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/apex-operators-expressions\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/10\\\/apex-operators-expressions-featured.png\",\"keywords\":[\"Apex\",\"Beginner\",\"Salesforce\",\"Salesforce Developer\"],\"articleSection\":[\"Salesforce\",\"Salesforce Developer\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/apex-operators-expressions\\\/\",\"url\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/apex-operators-expressions\\\/\",\"name\":\"Apex Operators and Expressions with Examples\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/apex-operators-expressions\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/apex-operators-expressions\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/10\\\/apex-operators-expressions-featured.png\",\"datePublished\":\"2026-09-02T13:30:00+00:00\",\"description\":\"Apex Operators explained with simple examples: arithmetic, comparison, logical, assignment, ternary, safe navigation and null coalescing.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/apex-operators-expressions\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/apex-operators-expressions\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/apex-operators-expressions\\\/#primaryimage\",\"url\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/10\\\/apex-operators-expressions-featured.png\",\"contentUrl\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/10\\\/apex-operators-expressions-featured.png\",\"width\":2400,\"height\":1260,\"caption\":\"Apex Operators featured image: title card with operator examples\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/apex-operators-expressions\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Apex Operators and Expressions with Simple Examples\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/\",\"name\":\"Swapnil Zambare - Blog\",\"description\":\"Salesforce &amp; Tech Guides\",\"publisher\":{\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/#organization\",\"name\":\"Swapnil Zambare - Blog\",\"url\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/09\\\/site-icon-512.png\",\"contentUrl\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/09\\\/site-icon-512.png\",\"width\":512,\"height\":512,\"caption\":\"Swapnil Zambare - Blog\"},\"image\":{\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.linkedin.com\\\/in\\\/theSwapnilZambare\"]},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/#\\\/schema\\\/person\\\/922ac0131aaa7088c78c2cb1700e0c9a\",\"name\":\"Swapnil Zambare\",\"sameAs\":[\"https:\\\/\\\/swapnilzambare.com\\\/blog\"],\"url\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/author\\\/swapnil-zambare\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Apex Operators and Expressions with Examples","description":"Apex Operators explained with simple examples: arithmetic, comparison, logical, assignment, ternary, safe navigation and null coalescing.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/swapnilzambare.com\/blog\/apex-operators-expressions\/","og_locale":"en_US","og_type":"article","og_title":"Apex Operators and Expressions with Examples","og_description":"Apex Operators explained with simple examples: arithmetic, comparison, logical, assignment, ternary, safe navigation and null coalescing.","og_url":"https:\/\/swapnilzambare.com\/blog\/apex-operators-expressions\/","og_site_name":"Swapnil Zambare - Blog","article_published_time":"2026-09-02T13:30:00+00:00","og_image":[{"width":2400,"height":1260,"url":"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/10\/apex-operators-expressions-featured.png","type":"image\/png"}],"author":"Swapnil Zambare","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Swapnil Zambare","Est. reading time":"8 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/swapnilzambare.com\/blog\/apex-operators-expressions\/#article","isPartOf":{"@id":"https:\/\/swapnilzambare.com\/blog\/apex-operators-expressions\/"},"author":{"name":"Swapnil Zambare","@id":"https:\/\/swapnilzambare.com\/blog\/#\/schema\/person\/922ac0131aaa7088c78c2cb1700e0c9a"},"headline":"Apex Operators and Expressions with Simple Examples","datePublished":"2026-09-02T13:30:00+00:00","mainEntityOfPage":{"@id":"https:\/\/swapnilzambare.com\/blog\/apex-operators-expressions\/"},"wordCount":1458,"publisher":{"@id":"https:\/\/swapnilzambare.com\/blog\/#organization"},"image":{"@id":"https:\/\/swapnilzambare.com\/blog\/apex-operators-expressions\/#primaryimage"},"thumbnailUrl":"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/10\/apex-operators-expressions-featured.png","keywords":["Apex","Beginner","Salesforce","Salesforce Developer"],"articleSection":["Salesforce","Salesforce Developer"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/swapnilzambare.com\/blog\/apex-operators-expressions\/","url":"https:\/\/swapnilzambare.com\/blog\/apex-operators-expressions\/","name":"Apex Operators and Expressions with Examples","isPartOf":{"@id":"https:\/\/swapnilzambare.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/swapnilzambare.com\/blog\/apex-operators-expressions\/#primaryimage"},"image":{"@id":"https:\/\/swapnilzambare.com\/blog\/apex-operators-expressions\/#primaryimage"},"thumbnailUrl":"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/10\/apex-operators-expressions-featured.png","datePublished":"2026-09-02T13:30:00+00:00","description":"Apex Operators explained with simple examples: arithmetic, comparison, logical, assignment, ternary, safe navigation and null coalescing.","breadcrumb":{"@id":"https:\/\/swapnilzambare.com\/blog\/apex-operators-expressions\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/swapnilzambare.com\/blog\/apex-operators-expressions\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/swapnilzambare.com\/blog\/apex-operators-expressions\/#primaryimage","url":"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/10\/apex-operators-expressions-featured.png","contentUrl":"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/10\/apex-operators-expressions-featured.png","width":2400,"height":1260,"caption":"Apex Operators featured image: title card with operator examples"},{"@type":"BreadcrumbList","@id":"https:\/\/swapnilzambare.com\/blog\/apex-operators-expressions\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/swapnilzambare.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Apex Operators and Expressions with Simple Examples"}]},{"@type":"WebSite","@id":"https:\/\/swapnilzambare.com\/blog\/#website","url":"https:\/\/swapnilzambare.com\/blog\/","name":"Swapnil Zambare - Blog","description":"Salesforce &amp; Tech Guides","publisher":{"@id":"https:\/\/swapnilzambare.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/swapnilzambare.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/swapnilzambare.com\/blog\/#organization","name":"Swapnil Zambare - Blog","url":"https:\/\/swapnilzambare.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/swapnilzambare.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/09\/site-icon-512.png","contentUrl":"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/09\/site-icon-512.png","width":512,"height":512,"caption":"Swapnil Zambare - Blog"},"image":{"@id":"https:\/\/swapnilzambare.com\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.linkedin.com\/in\/theSwapnilZambare"]},{"@type":"Person","@id":"https:\/\/swapnilzambare.com\/blog\/#\/schema\/person\/922ac0131aaa7088c78c2cb1700e0c9a","name":"Swapnil Zambare","sameAs":["https:\/\/swapnilzambare.com\/blog"],"url":"https:\/\/swapnilzambare.com\/blog\/author\/swapnil-zambare\/"}]}},"_links":{"self":[{"href":"https:\/\/swapnilzambare.com\/blog\/wp-json\/wp\/v2\/posts\/1216","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/swapnilzambare.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/swapnilzambare.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/swapnilzambare.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/swapnilzambare.com\/blog\/wp-json\/wp\/v2\/comments?post=1216"}],"version-history":[{"count":0,"href":"https:\/\/swapnilzambare.com\/blog\/wp-json\/wp\/v2\/posts\/1216\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/swapnilzambare.com\/blog\/wp-json\/wp\/v2\/media\/1213"}],"wp:attachment":[{"href":"https:\/\/swapnilzambare.com\/blog\/wp-json\/wp\/v2\/media?parent=1216"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/swapnilzambare.com\/blog\/wp-json\/wp\/v2\/categories?post=1216"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/swapnilzambare.com\/blog\/wp-json\/wp\/v2\/tags?post=1216"},{"taxonomy":"swapz_series","embeddable":true,"href":"https:\/\/swapnilzambare.com\/blog\/wp-json\/wp\/v2\/swapz_series?post=1216"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}