In this post, we will see Apex Primitive Data Types | Salesforce Development | Integer, Long, Double, Decimal, Blob, id etc.
Primitive Data Types in Apex
Primitive
Data Types:
        Basic Data Types which can not be defined
in terms of other data types.
Derived/Structured
Data Types:
        Data Types which can be defined in terms
of other data types.
e.g.
class
Syntax:
Data_Type
Variable = Literal;
e.g. Integer
x = 3;
| S.N. | Data Type | Description | 
| 1. | integer | ·    
  Used to save
  integer values ·    
  Variable
  occupies 32 bit memory ·    
  Range -231
  to 231-1 | 
| 2. | long | ·    
  Used to save
  integer values ·    
  Variable
  occupies 64 bit memory ·    
  Range -263
  to 263-1 | 
| 3. | double | ·    
  Used to save decimal point values e.g. 3.2 ·    
  Variable
  occupies 64 bit memory ·    
  Range -263
  to 263-1 | 
| 4. | decimal | ·    
  Used to save decimal point values e.g. 3.2 ·    
  Decimals
  have no bounds and can grow to any size | 
| 5. | string | ·    
  Used to save
  string value e.g. ‘Hello World’ ·    
  Value should
  be enclosed in single quote  e.g. ‘Parag Jambhulkar’ | 
| 6. | boolean | ·     Used to save boolean values i.e. true or false | 
| 7. | date | ·     Used to save date | 
| 8. | time | ·     Used to save time | 
| 9. | datetime | ·     Used to save date and time | 
| 10. | blob | ·    
  Saves binary
  data ·    
  Used to save
  any image, audio or multimedia file | 
| 11. | id | ·    
  Used to save
  Salesforce record id, object id or any kind of metadata id ·    
  It can be of
  15 digits or 18 digits ·    
  15 digit is
  case sensitive id ·    
  18 digit is
  case insensitive id ·    
  If you
  allocate 15 digit id then it get automatically converted to 18 digit id | 
Note: If you are not assigning any value to variable, then by default its value is set to null.
public class DataTypes {
public integer a=3;
public Long b=5L;
public double c=3.2;
public decimal d=5.7;
public string e='Parag Jambhulkar';
public boolean f=true;
//public date dd=Date.newInstance(year, month, day)
public date g=Date.newInstance(2022, 12, 26);
//public time hh=Time.newInstance(hour, minute, second, millisecond)
public time h=Time.newInstance(06, 30, 32, 5);
//public datetime ii= Datetime.newInstance(date, time)
public datetime i=DateTime.newInstanceGmt(g, h);
public blob j=blob.valueOf('paragjam');
public id k='0D5B000001DVM9t';
public void show()
{
system.debug('integer value:'+a);
system.debug('long value:'+b);
system.debug('double value:'+c);
system.debug('decimal value:'+d);
system.debug('string value:'+e);
system.debug('boolean value:'+f);
system.debug('date value:'+g);
system.debug('time value:'+h);
system.debug('datetime value:'+i);
system.debug('blob value:'+j);
system.debug('id value:'+k);
}
}
Program Code: (Anonymous Window)
DataTypes obj=new DataTypes();
obj.show();
 
No comments:
Post a Comment