Free Salesforce Developers Tutorials >

Chapter 3 - Apex Datatypes and Operators >

Rules of Conversion

Rules of Conversion

What You’ll Learn


S2 Labs

What Is Rule Of Conversions In Apex? 

In general, apex requires explicit conversion from one datatype to another however a few datatypes can be implicitly converted like variables of lower numeric type to higher types.

Hierarchy of numbers: integer<long<double<decimal

Note:

Once a value has been passed from a number of lower type to a number of higher type, the value is converted to the higher type of number.

  • Ids can always be assigned to strings.
  • String can be assigned to ids however at runtime the value is checked to ensure that it is a legitimate id, if it is not then a runtime error is thrown.
  • If the numeric value of the right hand side exceeds the maximum value for an integer you get a compilation error. In this case, the solution is to append L or l to the numeric value so that it represents a long value which has a wider range.
  • Arithmetic computation that produce values larger than the max values of the current type are set to overflow.

Example Of Rule Of Conversion 

 Integer i= 2147483647 + 1; // overflow

 

Download Study Material

Get access to exclusive study material for Salesforce Certification and ace your exams!

Download Now

Our Salesforce Certification Courses

Hey there! Glad you made it through our Salesforce Developer Training for beginners . But wait! We've got some high-in-demand Salesforce courses for you to take your Salesforce skills to the next level, making you a desired professional in the Salesforce job market.

Post a Comment

Your email address will not be published. Required fields are marked *