
- Apex 程式設計教程
- Apex - 首頁
- Apex - 概述
- Apex - 環境
- Apex - 示例
- Apex - 資料型別
- Apex - 變數
- Apex - 字串
- Apex - 陣列
- Apex - 常量
- Apex - 決策制定
- Apex - 迴圈
- Apex - 集合
- Apex - 類
- Apex - 方法
- Apex - 物件
- Apex - 介面
- Apex - DML
- Apex - 資料庫方法
- Apex - SOSL
- Apex - SOQL
- Apex - 安全性
- Apex - 呼叫
- Apex - 觸發器
- Apex - 觸發器設計模式
- Apex - 監管者限制
- Apex - 批處理
- Apex - 除錯
- Apex - 測試
- Apex - 部署
- 有用的 Apex 資源
- Apex - 快速指南
- Apex - 資源
- Apex - 討論
Apex - if 語句
一個 if 語句包括一個布林表示式,後面跟著一個或多個語句。
語法
if boolean_expression { /* statement(s) will execute if the boolean expression is true */ }
如果布林表示式計算結果為真,則 if 語句內的程式碼塊將被執行。如果布林表示式計算結果為假,則 if 語句結束後(在大括號後)的第一組程式碼將被執行。
流程圖

示例
假設我們的化工公司有兩個類別的客戶——高階和普通。應根據客戶型別,為他們提供折扣及其他福利,例如售後服務和支援。以下是對此的實現方法。
//Execute this code in Developer Console and see the Output String customerName = 'Glenmarkone'; //premium customer Decimal discountRate = 0; Boolean premiumSupport = false; if (customerName == 'Glenmarkone') { discountRate = 0.1; //when condition is met this block will be executed premiumSupport = true; System.debug('Special Discount given as Customer is Premium'); }
由於“Glenmarkone”是高階客戶,因此將基於該條件執行 if 塊。
apex_decision_making.htm
廣告