Friday, August 16, 2013

Data Types:

Data Types:
Each variable and expression belong to a specific data type.Different data types shown below
some primitive data types associate with methods
sObject data type shown below
A collection data type can store groups of elements of other primitive, composite, or collection data types.A collection data type does not have any restrictions on the number of elements it can hold.but you should be careful not to exceed the heap size.You use the limit methods to check the heap size.Collection data types shown below
List Data Type shown below
Set Data Type shown below
Map Data Type shown below

Developers use loop statements to repeatedly execute a set of statements.Apex supports following loop types do-while, while, traditional for loop, list or set iteration for loop, soql for loop.
Summary
some of the anonymous blocks examples are
//--------------------------------------------------------------------------------------------
//TASK 1: Create a Hello World anonymous block.
//TODO: Write a single line to output the text "Hello World!" to the results window
System.debug('Hello World!');

//--------------------------------------------------------------------------------------------
//TASK 2: Create a map of integers and check if the map contains a specific key.
//TODO: Instantiate a map called “numbers” that has an integer as keys and a string as values.
Map<Integer, String> numbers = new Map<Integer, String>();

//TODO: Create a FOR loop that loops 100 times and adds the values 0 thru 99 as the key and the string value of the number as the value of the map.
for (Integer i=0; i<100; i++){
  numbers.put(i, String.valueof(i));
}

//TODO: Create an IF statement that verifies that the map contains the value 35 and display the value using a System.debug statement.
if (numbers.containskey(35)){
   System.debug('The answer is: ' + numbers.get(35));
}

//--------------------------------------------------------------------------------------------
//TASK 3: Create a list of new accounts with unique names.
//TODO: Instantiate a list of Account data types
List<Account> accts = new List<Account>();

//TODO: Create a loop to add 20 new accounts to the list with a unique name for each account.
for (Integer i=0; i<20; i++){
  Account a = new Account(name='Account Name' + i);
  accts.add(a);

No comments:

Post a Comment