×
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 常量


与任何其他编程语言一样,常量是一旦声明或赋值就不改变它们的值的变量。

在Apex中,当我们想定义在整个程序执行过程中应该具有常量值的变量时,使用常量。 Apex常数用关键字'final'声明。


例如:

考虑一个CustomerOperationClass类和一个常量变量regularCustomerDiscount,在它里面:

public class CustomerOperationClass {
    static final Double regularCustomerDiscount = 0.1;
    static Double finalPrice = 0;
    public static Double provideDiscount (Integer price) {
        //calculate the discount
        finalPrice = price - price*regularCustomerDiscount;
        return finalPrice;
    }
}


要查看上述类的Output,您必须在开发人员控制台匿名窗口中执行以下代码:

Double finalPrice = CustomerOperationClass.provideDiscount(100);
System.debug('finalPrice '+finalPrice);

分类导航

关注微信下载离线手册

bootwiki移动版 bootwiki
(群号:472910771)