Showing posts with label apex basics. Show all posts
Showing posts with label apex basics. Show all posts

Thursday, 15 June 2017

Apex Primitive Data Types in Salesforce

Apex Primitive Data Types in Salesforce

Data type: data type in the apex tells about what type of data can be stored 
What is the range of the data that can be stored? 
a) Primitive data types
b) Collections 
c) Enums 

1. Primitive data types:

These are the data types which are predefined by the apex
a) A primitive data types such as an integer, double, long, date, date time, string, id or Boolean
All primitive data types are passed by value, not by reference.
All apex variable, whether they are class member’s variables, are initialized to null. make sure that we initialize variables to appropriate values before using them.

Apex primitive data type include:

Boolean: a value that can only be assigned true, false or null
            Eg: Boolean is active false;
       
Date: a value that indicates a particular day. date value contains no information about time, date value must always be created with a system static method.
            Eg: date my date=date. New instance (2013/05/15);
                     Output is 2013/05/15   00:00:00;

Time and date time:

These are date type associated with dates and times along with date data type. The time data type    stores times (hours, minutes, second and milliseconds). The date time data types stores dates (year month and date). The date time data type stores both dates and times.
           
Each of these classes has.A new instance with which we can construct particular date and time value.

       Eg: time t1 = new instance (19,20,1,20);
              o/p is 19:20;01  
We can also create dates and times from the current clock.
Date my =datetime.now();
Date t =date.today();

The date and time classes also have instance methods for converting from one format to another  

Eg: time t2 = date time.now().time();
We can also manipulate values by using a range of instance methods
Eg:      Date t3 = date.today(0);
          Date next =t3.adddays(30);
          We will get something like this as the output.
           2013-05-15   00:00:00
           2013-06-16   00:00:00

Saturday, 10 June 2017

Apex Introduction and Overview

Apex Introduction and Overview

Apex is strongly typed object oriented programming language
A.It allows the develops execute flows and transaction control statement.
B.Apex enables developers to add business logic to most system events like button click related records updates and visual force pages.
C.Apex languages
1.       Integrated: it provides built in support for DML calls.
2.       Inline salesforce object query language:
3.       Easy to use.
4.       Easy to test.
5.       Version
6.       Multi-tenant aware

When should I use apex:
A.      To create email services
B.      Create web services
C.      Perform complex validation over multiple objects.
D.      To create complex business processes that are not supported by work flow.
E.       Create custom transaction logic
F.       Attach custom logic to another operation.

How does apex work:

All apex programmers entirely on-demand on force.com platform.

When the developer writes and server Apex code to the platform

A.First the platform application serves compiles the code into abstract set of instruction that can be understood by apex run time interpreter.

B.The compile code is stored to meta data.

C.When the end uses triggers the execution of apex by clicking button visual force page the application services retrieves the compiled instructions from the meta data and send them to run time interpreters before returning the result.