Karthik online training

Thursday, 30 July 2015



                                                                  Vlookup
 
Hi All, 

 I came with one more interesting concept, V look up in Salesforce.
Q: First of all will see why salesforce introduce the Vlookup?
Ans: By using Vlookup, we will match the values in your organization.
Example:
I am taking custom objects
    1.       Candidate
    2.       Positions
EX: if Candidate already applied for that position or that particular position then we will add the validation.

First what’s the syntax of Vlookup:
VLOOKUP(field_to_return, field_on_lookup_object, lookup_value) ,
Steps to Create Vlookup:

Step 1:
Creating 2 Custom objects Candidate, Positions
Step 2:
Add the validation on Candidate custom Object



Step 3:
(VLOOKUP($ObjectType.Position__c.Fields.Name ,  $ObjectType.Position__c.Fields.Name ,  Applying_Position__c)) !=   Applying_Position__c
In the above code first we specify the Return type means, 
it will return all the Position Names in your org,
Second Parameter is, I am passing the value to Position object nothing but I am comparing Candidate Apply position with Position Name. If it matches then we are returning the first Parameter.
Third one is value in Candidate object.
Finally I am comparing the return type and Applying position in Candidate object if it match then we are allowing to store the data,
If it’s not matching, i will show an error message given below





Important points about Vlookup:

   1.    VLOOKUP available only in the  Validation Rules.
   2.    The field_to_return must be an auto number, roll-up summary, lookup relationship, 
      master-detail relationship, checkbox, date, date/time, email, number, percent, phone picklist,          text, text area, or URL field type.
3.       The field_on_lookup_object and lookup_value must be the same data type.

Hope you like this Concept.
Have a great day. Tomorrow i will come with one more interesting concept.


Thursday, 23 July 2015



                                          Bucket fields in Salesforce

Using of bucket fields we will categorize the Report Records without having Formula or Custom fields.
We can add upto five buck fields per an object and we can add 20 buckets.
Create a bucket field, you define multiple categories (buckets) that are used to group report values. We have created simple step by step instructions on how to create this report.
We can group by only Text, Number and Picklist datatypes.
Steps to create Bucket fields in Salesforce:
How to categorize the Reports based on the Salary.
Step 1:
Click on the Reports tab & New Report,

Step 2:
Select the object, on which object you want to create a report, I am planning to create a report on Location custom object.

Step 3:
Double click on the bucket fields

Step 4:
Specify your bucket field Name (Salary Range) And your condition.

Step 5:
Go to report builder and create a Summary report, and group by your bucket field and Name.
See the output.
Important points about bucket fields:
We can filter the bucket fields just like our normal field,

Hope you like this topic





Wednesday, 15 July 2015

Hi Guys!!
I came up with today's topic.

Comparison Operators in SOQL:    
Using of this comparison operator we will compare the values in where Condition.

              Operator                             
Description
=
Equals (Using of the Equals We will compare two different values)
Return true if both values compare.
!=
Not Equals (Using of the Not Equals We will compare two Different values)
Return true if both values not compare.
< 
Less than
<=
Less than or equal
> 
Greater than
>=
Less than or equal
> 
Greater than
>=
Greater than or equal
IN
In
NOT IN
Not in (WHERE clause)
INCLUDES EXCLUDES
Applies to multi-select picklists


Some Examples on SOQL:      
I want display all the accounts in a Table ? What we need to do?                  
Page:
 <apex:page controller="SOQLDemo" sidebar="false">
     <apex:form >
         <apex:pageBlock title="SOQL Demo">
             <apex:pageBlockSection title="SOQL Demo" columns="1">
                 <apex:pageBlockTable value="{!Accountdata}" var="s">
                     <apex:column value="{!s.Name}"/>
                     <apex:column value="{!s.ID}"/>
                     <apex:column value="{!s.Phone}"/>
                 </apex:pageBlockTable>       
             </apex:pageBlockSection>
         </apex:pageBlock>        
     </apex:form>
</apex:page> 
Class:
public class SOQLDemo
{   
    public  list<Account> Accounts{get;set;}
    Public list<Account> getAccountdata()
    {
        Accounts = [select id,Name,phone from Account];
        return Accounts ;        } }

SOQL Joins & Soql Locking statements:
Using of the SOQL Joins we will retrieve the data from their related object.
Example:

Q1. I want to write a query on Child object and we need to retrieve their related Parent records?
              Select id,Name,Phone,Email,Account.Name from contact
We are writing query on Parent object and we are retrieving the records from their related Parent.

Q2. I want to write a query on Parent object and we need to retrieve their related child records?
                Select id,Name,(select id,Name from contact) from Account
Here we are retrieving the Account their related contacts.

SOQL Locking Statement:

Using of the SOQL Update statement we will lock the SObject records in Salesforce. While a sObject record is locked, no other client or user is allowed to make updates either through code or the Salesforce user interface. The lock gets released when the transaction completes.
Syntax: Select id,Name,Phone from Account where Name=’IBM’ For Update;
During this transaction we cannot edit these IBM records using Data management Tools are UI.

Important Points on SOQL Update:

  •       While the records are locked by a client, the locking client can modify their field values in the database in the same transaction.
  • Other clients have to wait until the transaction completes and the records are no longer locked before being able to update the same records. Other clients can still query the same records while they’re locked
  •   We cannot specify the Order by if you are using SOQL update statement.
  •   The Apex runtime engine locks not only the parent sObject record but all child records as well. So if you lock the parent object records all the associate child records also got locked.   Syntax:
                Select Field1, Field 2, Field 3 --- from Object FOR Update



Example Code:

Public class SOQLlocking
{
                Public list<Account> getAccountRecords()
{
list<Account> AccountRecords = [select id,Name,Phone from Account where Name Like     ‘%Karthik Training%’ FOR Update];
return AccountRecords;
}
}
In the above Code I lock all the Karthik Training records, while this transaction  any user try to change the record user will notify with the error.
Once the transaction completed then we will update this records also.

 SOQL Interview questions:

     1. What is SOQL?
SOQL stands for Salesforce object query language, using of the SOQL we will retrieve the data from single object and related object.
Ex: if we want to retrieve the data from Account object,

    Select id,Name,Phone  from Account

      2. What are the Governor limits of SOQL?
We will write maximum of 100 SOQL, using of one SOQl we will retrieve 50000 records.
Total number of SOQL queries issued for Batch Apex and future methods is 200

3   3.  What is the return type for SOQL queries?
Soql will return Integer datatype, List of Sobject and Single subject.








Thursday, 2 July 2015

Hi Guys..
I came up with today's topic..

About SOQL

SOQL Stands of Salesforce object query language, Using SOQL we will retrieve the data from Single object and their related objects. SOQL are similar to SQL queries but it is designed specifically for Salesforce.

Syntax of SOQL:
                Select field1,field2,field3----- from object

Our list will return the list data and it's in order format.
If we want we can add the conditions to your Select query.

Syntax:

Single where Condition
Select field1,field2,field3----- from object where Condition1           
select id,Name,Phone from Account

Multiple conditions:
            Select field1,field2,field3----- from object where Condition1 AND Condition 2-----etc
            Select id,Name,Phone from Account where Name=’IBM’ AND Name = ‘CSC’

Like Operator:
Using of this like operator we will match the key value.

Ex:       Select field1,field2,field3----- from object where Field  LIKE ‘%key%’
            Select id,Name,Phone from Account where Name LIKE ‘%IBM%’
In the Name wherever it find the IBM text it will fetch all the value.

 Sorting:
Ascending order:
We can sort the SOQL result in Ascending order.

Ex: Select field1,field2,field3----- from object Order BY Field asc
       Select id,Name,Phone from Account Order BY Name asc;

Descending order:
We can sort the SOQL result in Descending order.

Ex: Select field1,field2,field3----- from object Order BY Field desc
       Select id,Name,Phone from Account Order BY Name desc;

Limit:
 Using of limit statement we will limit the Values
 
      Ex: Select field1, field2, field3----- from object limit 5
In the above query we will retrieve 5 Records from the object.
            Select id, Name, Phone from Account limit 5;
In the above query we will retrieve 5 Records from the object.

Count ();
Using of the count method we will calculate the number of values return in the query.


EX:       Select Count () from object
Hi Guys..
 Here is our today's concept..

What is Collection?

Collections are Nothing but Containers by using the Collections we will store the data we will retrieve the data and we will manipulate the data.
We are having 3 types of collections in Salesforce.

  •  List
  •  Set 
  • Map

  • List:
List is a ordered data, by using the list we will allow the duplicate values.


Syntax of a list:    list<Datatype> variable = new list<datatype> ();

Here list elements can be any datatype, either primitive datatypes (integer, string, date, datetime---etc.), Subject(standard or custom object) and Collections(list,set Map).

First value in the list always store into index “0” position.

For example:
 I am storing multiple values in the list like ‘Karthik’ ,’Kumar’,’Raj’,’Rani’----,karthik will store into index zero position and kumar will store into index 1 position and Raj will store into index 2 position.

       Index 0             index 1              index 2           indexes 3
            Karthik             Kumar                  Raj                     Rani

Lists can contain any collection and can be nested within one another and become multidimensional. For example: you can have a list of lists of sets of Integers. A list can contain up to four levels of nested collections inside it, that is, a total of five levels overall.

Ex: list<list<list<list<list<Datatype>>>>>Variable = new list<list<list<list<list<Datatype>>>>> ();


List Methods:

Add:
Using Add method we will add the values to our list

Ex:         list<string> s = new list<string>{‘Karthik’,’kumar’,’karthik’,’Raj’};
                system.debug(‘$$$$$$’+s);
                Output: Karthik, kumar, karthik, Raj

Add (index, listElement):
We can add the list value into the list at specified index position.

Ex: list<string> s = new list<string>{'Karthik','kumar','karthik','Raj'};
       S.add(2,'karthik Training');
      System. Debug('$$$$$$'+s);
Output:    Karthik, kumar, karthik Training, karthik, Raj

Add All();
Add all of the elements in the specified list to the list that calls the method. Both lists must be of the same type.
              
Ex:  list<string> s = new list<string>{'Karthik','kumar','karthik','Raj'};
              System.Debug('$$$$$$'+s);
                list<string> s1 = new list<string>{'IBM’,'TCS','CSC','CTC'};
              s1.addall(s);
                System.Debug('$$$$$$'+s1);

Output: IBM, TCS, CSC, CTC, Karthik, kumar, karthik, Raj

Clear ():
By using of the clear method we will clear the values from the list.

Ex: list<string> s = new list<string>{'Karthik','kumar','karthik','Raj'};
                s.clear();
              System.Debug('$$$$$$'+s);

Output :  {}(Blank)

Clone ():
Using the clone method we will clone the values from the list.

Ex:  list<string> s = new list<string>{'Karthik','kumar','karthik','Raj'};
       list<string> s1 = s.clone();
      System.Debug('$$$$$$'+s1);

Size ():
Returns the number of elements in the list.

EX:  list<string> s = new list<string>{'Karthik','kumar','karthik','Raj'};
       list<string> s1 = s.size();
      System.Debug('$$$$$$'+s1);

Note: There is no limit on Number of items a collection can hold. But we need to check the heap size .

  • Set:
Set is an UN Ordered data, set will not allow the duplicate values.

Syntax of a List:
                Set<datatype> variable = new set<datatype> ();

Important methods in Set:
Add: 
By using add method we will add the values to our list.

Ex: set<integer> s = new set<integer>{3,5,1,7,3,6,12,15,34};
                system.debug(‘$$$$$$’+s);

                Output: 1, 3, 5, 6, 7, 12, 15, 34

Add all:
By using add all method we add all values to our set.

Ex: set<integer> s = new set<integer>{3,5,1,7,3,6,12,15,34}  ;
                list<integer> slist = new list<integer>{200,201,202,203,204,205};
                s.addall(slist);
                system.debug(‘$$$$$$’+s);

Output:  1, 3, 5, 6, 7, 12, 15, 34, 200, 201, 202,203,204,205

Clear ():
By using of clear method we will clear the values from set.

Ex: set<integer> slist = new set<integer>{200,201,202,203,204,205};
                s.clear();

Output:

Clone();
By using the clone method we will clone the values from set.

syntax: set<integer> s = new set<integer>{1,5,2,4,3,5,8};
                set<integer> s1 = s.clone();
                system.debug(‘$$$$$$’+s1);
                Output: 1, 2, 3, 4, 5, 8
Size():
Using of size method we will calculate the number of components in the set.

Ex: set<integer> s = new set<integer>{1,5,2,4,3,5,8};
                system.debug(‘$$$$$$’+s.size());

                Output: 6


  • Map:
Map is a combination of key value pairs, map will allow the duplicate values but it will not allow the duplicate key.

Syntax:
map<key_datatype,value_datatype> variable = new map<key_datatype,value_datatype>();

Map methods:

Clear ():
By using clear method we will clear the values from Map.

Ex:  map<string,integer> s = new map<string,integer>{‘IND’ => 91,’US’ => 1 ,’UK’ =>2 ,’USSR’ => 3,’SL’ => 2}
s.clear();
System.debug(‘$$$$’+s);

Keyset():
Using of the key set we will get only the key’s from the map.

Ex: map<string,integer> s = new map<string,integer>{‘IND’ => 91,’US’ => 1 ,’UK’ =>2 ,’USSR’ => 3,’SL’ => 2}
System.debug(‘$$$$’+ s.keyset());

Output:  IND, SL, UK, US, USSR

Values ():
 By using of values method we will add the values from map

Ex: map<string,integer> s = new map<string,integer>{‘IND’ => 91,’US’ => 1 ,’UK’ =>2 ,’USSR’ => 3,’SL’ => 2}
System.debug(‘$$$$’+ s.values());

Output:  91, 1, 2, 3, 2

Interview questions on Collections:

Q. What is a Collection? How many types of collections we have?
Ans: Collections are nothing but container, using of collections we will store the data , retrieve the data and manipulate the data.
We are having 3 types of collections in salesforce.

  •   List
  •   set
  •   map

Q. What is the difference between list and set?
Ans:      

  • list is a ordered data and list will allow the duplicate values, first value in the list always store   into index zero position.

  • Set is a UN ordered data set will not allow the duplicate values.