Friday, May 26, 2017

Salesforce Collections.

Salesforce Collections 
(List, Set & Map)

List:
→ List is a collection of elements, Such as primitive data types (String, Integer, Date, etc), user defined objects, sObjects, Apex objects or other collections (can be multidimensional up to 5 levels).
→ List allows duplicate values.
→ List index position starts from zero.

Syntax: List<datatype> listName = new List <datatype>();

List Methods:

1. add()
→ Add value in List.
→ Ex.
     List <string> fruits = new List <string>();
     fruits.add('Apple');
     fruits.add('Orange');
     fruits.add('Banana');
     fruits.add('Grape');

OR

List <string> fruits = new List <string>{'Apple','Orange','Banana','Grape'};

2. get()
→ Retrieve a value from the list using Index.
→ Ex.
     String getfruit = fruits.get(1);
          - We get 'Orange' fruit form list using getfruit variable.

3. set()
→ Replace a value with the value at given Index parameter.
→ Ex.
     fruits.set(3,'Strawberry');  
          - In List value has been changed at the index 3. 'Grape' is replace to 'Strawberry'

4. size()
→ Return the number of elements in the List.
→ Ex.
     fruits.size();
          - Give the size of fruits list is 3.

5. clear()
→ Remove the elements from the list.
→ Ex.
     fruits.clear();          

For more List methods.


Set:
→ Set is a collection of unique, unordered elements.
→ It can contain primitive data types (String, Integer, Date, etc) or sObjects.
→ Set allows unique values.

Syntax: Set<datatype> SetName = new Set <datatype>();

Set Methods:

1. add()
→ Adds an element to the set if it is not already present.

2. contains()
→ Returns true if the set contains the specified element.

3. equals()
→ Compares this set with the specified set and returns true if both sets are equal; otherwise, returns false.

4. size()
→ Returns the number of elements in the set.

5. remove()
→ Removes the specified element from the set if it is present. 

For more Set methods


Map:
→ Map is a collection of key-value pair.
→ Keys can be any primitive data types (String, Integer, Date, etc) while values can include primitives, Apex objects, sObjects and other collections.
→ Map allows duplicate values, but each key must be unique.

Syntax: map<datatype,datatype> MapName = new map <datatype,datatype>();

Map Methods:

1. get(key)
→ Returns the value to which the specified key is mapped, or null if the map contains no value for this key.

2. put(key, value)
→ Associates the specified value with the specified key in the map.

3. remove(key)
→ Removes the mapping for the specified key from the map, if present, and returns the corresponding value.

4. size()
→ Returns the number of key-value pairs in the map.

5. values()
→ Returns a list that contains all the values in the map.

For more Map methods




Saturday, May 20, 2017

Apex - Primitive Data types

Apex - Primitive Data types
    • Integer
    • Decimal
    • Double
    • Long
    • Date
    • Datetime
    • String
    • ID
    • Boolean
       1.      Integer
             → 32-bit number without include decimal point.
             → Ex:
       Integer intNumber = 70;
       system.debug('Value of intNumber variable -> '+ intnumber);
     
     2.      Decimal
           → A number that includes a decimal point.
           → Decimal is an arbitrary precision number.
           → Currency fields are automatically assigned the type Decimal.
        
     3.      Double
           → 64 - bit number that includes a decimal point.
           → Doubles have a minimum value of -263 and a maximum value of 263-1
           → Ex:
        double pi = 3.14159;
        system.debug('Value of pi variable -> '+ pi);

     4.      Long
           → 64 - bit number that does not include a decimal point.
           → Longs have a minimum value of -263 and a maximum value of 263-1.
           → Use this data type when you need a range of values wider than the range provided by Integer.
           → Ex:
        Long ln = 214748985683648L;
        system.debug('Value of long variable -> '+ ln);

      5.      Date
           → A value that indicates a particular day.
           → Date values not contain information about time.
           → Date values must always be created with a system static method.
           → Ex:
        Date dtDate = date.today();
        System.debug('Today Date -> '+dtDate);

     6.      Datetime
           → A value that indicates a particular day and time, such as a timestamp.
           → Datetime values must always be created with a system static method.

     7.      String
           → Set of meaningful characters surrounded by single quotes.
           → It does not have limit on the number of characters they can include.
           → Instead, the heap size limit is used to ensure that your Apex programs don't grow too large.
           → Strings can be manipulated with several standard methods.
           → Ex:

         String specialStr = 'The quick brown fox jumped over the lazy dog.';
         System.debug('Special string -> ' + specialStr);

     8.      ID
           → Any valid 18-character Force.com record identifier.
           → If you set ID to a 15-character value, Apex converts the value to its 18-character representation.
           → Ex:
           ID id='00300000003T2PGAA0';

     9.      Boolean
           → A value that can only be assigned true, false, or null.
           → This type of variables can be used as flag in programming to identify the particular condition set or not set.
           → Ex:
           Boolean youCan = true;



Sunday, May 14, 2017

How to create Custom Object

How to create Custom Object

Step 1: Go to Setup and then search for 'Object' as shown below. Then click on the Objects link as shown below



Step 2: Once the object page is opened, then click on the 'Create New Object' button as shown below


Step 3: After clicking on button, new object creation page will appear and then enter all the object details as entered below. 

→ Object name should be Student. You just have to enter the information in the field as shown in below screenshot and keep other default things as it is.




→ Enter the information and then click on 'Save' button


→ By following above steps, we have successfully created the "Student" object.

Creating the Custom Fields for Student object

Step 1: We will be creating a field named as 'Mobile Number' of data type as Number. Go to Setup and click on it.


Step 2: Search for 'Object' as shown below and click on it


Step 3: Click on object 'Student'.


Step 4: Once you have clicked on Student object link and the object detail page appears, click on the New button.


Step 5: Then select the data type as Number and click next.


Step 6: Enter the field name and label as shown below


Step 7: Click on Visible and then click Next.


→ Click on 'Save' button.


→ By following above steps, our custom field 'Mobile Number' is created. 
→ You have to follow all above custom field creation steps for remaining fields. 

→ This is the final view of "Student" object once all field are created.