About Salesforce
Salesforce is a cloud-based online solution for customer relationship management or CRM. Salesforce provides all of our departments like marketing, sales, commerce, and service with a shared view of our customers with a single integrated CRM platform.
Apex is a strongly typed, object-oriented programming language that allows developers to execute flow and transaction control statements on Salesforce servers in conjunction with calls to the API. Using syntax that looks like Java and acts like database stored procedures, Apex enables developers to add business logic to most system events, including button clicks, related record updates, and Visualforce pages. Apex code can be initiated by Web service requests and from triggers on objects. Salesforce Apex Primitive datatypes are, Blob, Boolean, Date, DateTime, Decimal, Double, ID, Integer, Long, Object, String and Time.
Reading this article, you can learn and test the Apex primitive datatypes in SalesForce.
The prerequisites for testing Apex primitive datatypes in SalesForce as, Register a Salesforce Free Trial account using the following
link.
Step 1
Log into your Salesforce Account and click the Developer Console.
Step 2
Now, we can create new Apex Class ApexDatatype and the file named as ApexDatatype.apxc,
After creating Apex class ApexDatatype,
Add a DTtest method for create and test primitive datatypes,
Step 3
The first primitive datatype is, Blob - A collection of binary data stored as a single object. For example,
- String tStr='CsharpCorner';
- Blob myBlob=blob.valueOf(tStr);
- String dStr=myBlob.toString();
- System.debug('Blob Content is : '+ dStr);
Next we have, Boolean data type- A value that can only be assigned true, false, or null.
- Boolean isRollno = true;
- System.debug('Boolean Values is : '+ isRollno);
Next we have, Date data type -A value that indicates a particular day. Unlike
Datetime values, Date values contain no information about time.
- Date todate = date.today();
- System.debug('ToDate is : '+ todate);
Next we have, DateTime data type - A value that indicates a particular day and time, such as a timestamp.
- Datetime fixdatetime=Datetime.now();
- System.debug('fixdatetime is : '+ fixdatetime);
Next we have, Decimal data type -A number that includes a decimal point. Decimal is an arbitrary precision number. Currency fields are automatically assigned the type Decimal,
- Decimal feeamount=154.70;
- System.debug('FeeAmount(Decimal) is : '+ feeamount.abs());
Next we have, Double data type -A 64-bit number that includes a decimal point.
- Double scient=154.70;
- System.debug('scient(Double) is : '+ scient);
Next we have, ID data type - Any valid 18-character Force.com record identifier.
- ID recordid='00400000003MKSBB01';
- System.debug('recordid is : '+ recordid);
Next we have, Integer data type - A 32-bit number that does not include a decimal point. Integers have a minimum value of -2,147,483,648 and a maximum value of 2,147,483,647.
- Integer Mark = 95;
- System.debug('Mark is '+ Mark);
Next we have, Long data type - A 64-bit number that does not include a decimal point.
- Long RegNo = 52412548711L;
- System.debug('RegNo is '+ RegNo);
Next we have, String data type - Any set of characters surrounded by single quotes.
- String text = 'Welcome to CSharp Corner';
- System.debug('text is '+ text);
Finally we have, Time data type - A value that indicates a particular time.
- DateTime dt = Datetime.now();
- Time myTime = Time.newInstance(dt.hour(), dt.minute(), dt.second(),
- dt.millisecond());
- System.debug('Time is '+ myTime);
Finally, the ApexDatatype.apxc class code is,
- public class ApexDatatype {
- public static void DTtest() {
-
- String tStr = 'CsharpCorner';
- Blob myBlob = blob.valueOf(tStr);
- String dStr = myBlob.toString();
- System.debug('Blob Content is : ' + dStr);
-
- Boolean isRollno = true;
- System.debug('Boolean Values is : ' + isRollno);
-
- Date todate = date.today();
- System.debug('ToDate is : ' + todate);
-
- Datetime fixdatetime = Datetime.now();
- System.debug('fixdatetime is : ' + fixdatetime);
-
- Decimal feeamount = 154.70;
- System.debug('FeeAmount(Decimal) is : ' + feeamount.abs());
-
- Double scient = 154.70;
- System.debug('scient(Double) is : ' + scient);
-
- ID recordid = '00400000003MKSBB01';
- System.debug('recordid is : ' + recordid);
-
- Integer Mark = 95;
- System.debug('Mark is ' + Mark);
-
- Long RegNo = 52412548711 L;
- System.debug('RegNo is ' + RegNo);
-
- String text = 'Welcome to CSharp Corner';
- System.debug('text is ' + text);
-
- DateTime dt = Datetime.now();
- Time myTime = Time.newInstance(dt.hour(), dt.minute(), dt.second(), dt.millisecond());
- System.debug('Time is ' + myTime);
- }
- }
Step 4
For Debugging the Apex class ApexDatatype, Click Debug menu and Select Open Execute Anonymous Window,
Now, Write the Apex code for calling DTtest method, and enable the Open log option for Viewing output and click Execute,
ApexDatatype.DTtest();
Step 5
Now we can verify the output, After clicking Execute, Log will be open automatically and select Debug Only option,
Summary
Now, you have successfully tested the Apex primitive datatypes in the Salesforce environment.