×
Apex 编程教程Apex 环境Apex 示例Apex 数据类型Apex 变量Apex 字符串Apex 数组Apex 常量Apex 决策Apex 循环Apex 集合Apex 类Apex 类方法Apex 对象Apex 接口Apex DMLApex 数据库方法Apex SOSLApex SOQLApex 安全性Apex 调用Apex 触发器Apex 触发设计模式Governer Limits调节器限制Apex 批量处理Apex 调试Apex 测试Apex 部署Apex 字符串Apex 数组

Apex if语句


Apex 决策Apex 决策


if语句

if语句由布尔表达式后跟一个或多个语句组成。

语法:

if boolean_expression {
   /* statement(s) will execute if the boolean expression is true */
}
如果布尔表达式的计算结果为true,那么if语句中的代码块将被执行。 如果布尔表达式的计算结果为false,那么第一组代码在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 决策Apex 决策


分类导航

关注微信下载离线手册

bootwiki移动版 bootwiki
(群号:472910771)