Apex Programming Tutorial
Apex Useful Resources
Selected Reading
- Apex - Deployment
- Apex - Testing
- Apex - Debugging
- Apex - Batch Processing
- Apex - Governer Limits
- Apex - Trigger Design Patterns
- Apex - Triggers
- Apex - Invoking
- Apex - Security
- Apex - SOQL
- Apex - SOSL
- Apex - Database Methods
- Apex - DML
- Apex - Interfaces
- Apex - Objects
- Apex - Methods
- Apex - Classes
- Apex - Collections
- Apex - Loops
- Apex - Decision Making
- Apex - Constants
- Apex - Arrays
- Apex - Strings
- Apex - Variables
- Apex - Data Types
- Apex - Example
- Apex - Environment
- Apex - Overview
- Apex - Home
Apex Useful Resources
Selected Reading
- Who is Who
- Computer Glossary
- HR Interview Questions
- Effective Resume Writing
- Questions and Answers
- UPSC IAS Exams Notes
Apex - Constants
Apex - Constants
As in any other programming language, Constants are the variables which do not change their value once declared or assigned a value.
In Apex, Constants are used when we want to define variables which should have constant value throughout the program execution. Apex constants are declared with the keyword final .
Example
Consider a CustomerOperationClass class and a constant variable regularCustomerDiscount inside it −
pubpc class CustomerOperationClass { static final Double regularCustomerDiscount = 0.1; static Double finalPrice = 0; pubpc static Double provideDiscount (Integer price) { //calculate the discount finalPrice = price - price * regularCustomerDiscount; return finalPrice; } }
To see the Output of the above class, you have to execute the following code in the Developer Console Anonymous Window −
Double finalPrice = CustomerOperationClass.provideDiscount(100); System.debug( finalPrice +finalPrice);Advertisements