Karthik online training

Friday, 14 August 2015

TreeView in SalesForce

                                                                      TreeView  

How to implement Treeview in our Salesforce?
Here, in our example i am populating Account and it's related contacts.

public class Treeview
{
    public list<Childrecords> Assigning1{get;set;}
    public integer i;
    public string AccountName{get;set;}
    public class Childrecords
    {
        public list<contact> contactsrecords{get;set;}
        public Account Accountrecords{get;set;}
        public Childrecords(Account acc,list<contact> con)
        {
            Accountrecords= acc;
            contactsrecords = con;
        }
  
    }
    public list<Childrecords> getmethoddemo()
    {
        Assigning1 = new list<Childrecords>();
        list<Account> acc1 = new list<Account>();
        AccountName = '%'+AccountName+'%';
        string AccountName1 = AccountName ;
        if(AccountName1 !='%null%' )
        {
            acc1 = [select id,Name,Rating,Phone from Account where Name LIKE:AccountName1 limit 50];
        }
        else
        {
            acc1 = [select id,Name,Rating,Phone from Account limit 50];
        }
        for(integer i=0;i<acc1.size();i++)
        {
            list<Contact> Con2 = [Select id,LastName,Phone,AccountID,Email from contact where AccountID=:acc1[i].ID];
            Assigning1.add(new Childrecords(acc1[i],Con2));
        }
        return Assigning1;
    }
}


Page:


<apex:page Controller="Treeview">
    <apex:form >
        <apex:pageBlock title="Account Treeview">
       
<!-- Include the Jquery Script files -->
    <link rel="stylesheet" href="{!URLFOR($Resource.TreeviewInSalesforce,'Jquerytreeview/jquery.treeview.css')}"/>
    <script src="{!URLFOR($Resource.TreeviewInSalesforce,'Jquerytreeview/jquery.js')}" type="text/javascript"></script>
    <script src="{!URLFOR($Resource.TreeviewInSalesforce,'Jquerytreeview/jquery.cookie.js')}" type="text/javascript"></script>
    <script src="{!URLFOR($Resource.TreeviewInSalesforce,'Jquerytreeview/jquery.treeview.js')}" type="text/javascript"></script>
<!-- End of Javascript files -->
<script type="text/javascript">
        $(function() {
            $("#tree").treeview({
                collapsed: true,
                animated: "medium",
                control:"#sidetreecontrol",
                persist: "location"
            });
        })
</script>
<br/>
<!-- Tree -->
<div class="treeheader" style="height:0px;">&nbsp;</div>
<div id="sidetreecontrol"><a href="?#"><font style="color:blue;">Collapse All</font></a> | <a href="?#"><font style="color:blue;">Expand All</font></a></div>
<br/>
<ul id="tree">
    <apex:repeat value="{!methoddemo}" var="MainMethodVar">
        <li>
            <table style="width:100%" >
                <tr style="width:100%">                   
                    <td style="width:30%">
                       <strong><apex:outputlink style="color:MidnightBlue;" target="_blank" value="/{!MainMethodVar.Accountrecords.ID}">{!MainMethodVar.Accountrecords.Name}</apex:outputlink></strong>                   
                    </td>
                    <td style="width:30%">
                         <strong><apex:outputtext style="color:MidnightBlue;" escape="false" value="{!MainMethodVar.Accountrecords.Phone}"/></strong>
                    </td>
                    <td style="width:40%">
                         <strong><apex:outputtext style="color:MidnightBlue;" escape="false" value="{!MainMethodVar.Accountrecords.Rating}"/></strong>
                    </td>
                </tr>
              </table>     
             <ul>
                 <apex:repeat value="{!MainMethodVar.contactsrecords}" var="child">
                    <li>
                    <table style="width:100%" >
                    <tr style="width:100%">
                   
                    <td style="width:30%">
                       <span class="formattextcon"><apex:outputtext style="color:red;" escape="false" value="{!child.LastName}"/></span>                   
                    </td>
                    <td style="width:30%">
                         <span class="formattextcon"><apex:outputtext style="color:red;" escape="false" value="{!child.Email}"/></span>
                    </td>
                    <td style="width:40%">
                         <strong><apex:outputtext style="color:MidnightBlue;" escape="false" value="{!child.Phone}"/></strong>
                    </td>
                </tr>
              </table>
                   
                                                 
                    </li>
                 </apex:repeat> 
             </ul> 
        </li>
    </apex:repeat>
</ul>
    </apex:pageBlock>
    </apex:form> 
</apex:page>


Hope you like this Concept :)

Have a great day. Tomorrow i will post one more useful concept.

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