Wednesday, 28 August 2013

sfdc

1.. Create and manage Assignment rules in Salesforce
Assignment rules are used to automate your organization’s lead generation and support processes.
·         Lead Assignment Rules – Specify how leads are assigned to users or queues as they are created manually, captured from the web, or imported via the lead import wizards.
·         Case Assignment Rules – Determine how cases are assigned to users or put into queues as they are created manually, using Web-to-Case, Email-to-Case, On-Demand Email-to-Case, the Self-Service portal, the Customer Portal, Outlook, or Lotus Notes.
Aim : All the cases created by user ‘jZaa’ should be assigned to ‘Jitendra Yahoo’.
To create this Assignment rule, go to Setup | App Setup | Cases | Assignment Rules and on right hand side click on New.
In first step, give the assignment rule name, lets say name is ‘to jitendra Yahoo’. You may have noted the check box which says “Set this as the active case assignment rule” click on this.
After creating rule, click on that rule and click on New.
Rule Entry for the Case Assignment in Salesforce
Rule Entry for the Case Assignment in Salesforce
As you can see in above screen shot, at step 1 enter the order in which this rule should be run, as there may be multiple rules in assignment.
in step 2 we can choose criteria or formula. here i have choose the option to create formula.
In step 3, i have written the formula that if user alias is ‘JZaa’
In step 4, i have assigned the case to user “Jitendra Yahoo” if formula comes true
and in step 5, i have assigned the email template which should be sent after assignment.
The working example of above rule is shown in below screen shot:
Assignment rule of salesforce in action
Assignment rule of salesforce in action
As you can see in above figure, Case created by JZaa is automatically assigned to the “Jitendra Yah00″ and those our assignment rule is working as expected.
Note : If there is no assignment rule then case is assigned to Creator itself.

 

2… Create a custom Web service in Salesforce and consume it in C#.Net application

In Previous article, we have consumed the standard enterprise wsdl of the salesforce. In this article we will create the webservice using apex in salesforce and consume it in C#.Net application.
In Salesforce create below class (using force.com IDE)
1
global public with sharing class SaveExpenditureWebService {
2


3
    webservice static Expenditure__c createExpenditure(Decimal amount,String expName, String paidByName )
4
    {

5
        Expenditure__c c = new Expenditure__c();
6
        Person__c p = [Select p.Name From Person__c p Where Name = :paidByName limit 1];

7
        c.Amount__c = amount;
8
        c.Name = expName;

9
        c.Exp_Date__c = Date.today();
10
        c.Paid_By__c = p.Id;

11
        insert c;
12


13
        return c;
14
    }

15
}
Note:
·         Apex class in which webservice is going to be written must be declared “global”.
·         Keyword “webservice” must be used for a method which should be exposed as a webservice.
·         Method must be declared as static.
In above code, I am using a custom object “Expenditure__c” to insert into Salesforce.  Any type of code can be written.
Now in C#, create windows application with following controls:
Create Custom web service in salesforce using apex and consume using C#.Net
Create Custom web service in salesforce using apex and consume using C#.Net
Add the reference to “enterprise WSDL” as shown in previous article.
Now, add the reference to newly created custom WSDL. (In Salesforce, go to the Apex classes and click on wsdl button to get the generated WSDL link)
In this case, name of web reference added is “SFDCCustom”.
Write below code, in c# application:
1
using System;
2
using System.Collections.Generic;

3
using System.ComponentModel;
4
using System.Data;

5
using System.Drawing;
6
using System.Linq;

7
using System.Text;
8
using System.Windows.Forms;

9
using SFDCWebServiceExample.SFDCCustom;
10
using SFDCWebServiceExample.SFDC_Enterprise_WSDL;

11
using System.Web.Services.Protocols;
12


13
namespace SFDCWebServiceExample
14
{

15
    public partial class AddExpenditure : Form
16
    {

17
        private SforceService binding;
18
        private LoginResult lr;

19
        private SaveExpenditureWebServiceService myBinding = newSaveExpenditureWebServiceService();
20


21
        public AddExpenditure()
22
        {

23
            InitializeComponent();
24
        }

25

26
        private void btnExpenditure_Click(object sender, EventArgs e)

27
        {
28
            if (login())

29
            {
30
                try

31
                {
32
                    #region[Consume Custome webservice]

33
                    //Code 2
34
                    myBinding.SessionHeaderValue = newSFDCCustom.SessionHeader();

35
                    myBinding.SessionHeaderValue. sessionId = lr.sessionId;
36


37
                    // Update: Copy the URL returned by login to the endpoint for our web service
38
                    int idx1 = lr.serverUrl.IndexOf(@"/services/");

39
                    int idx2 = myBinding.Url.IndexOf(@"/services/");
40
                    if (idx1 == 0 || idx2 == 0)

41
                    {
42
                        MessageBox.Show("Invalid URL strings in bindings");

43
                    }
44


45
                    myBinding.Url = lr.serverUrl.Substring(0, idx1) + myBinding.Url.Substring(idx2);
46


47
                    decimal amnt = 0;
48


49
                    Decimal.TryParse( txtAmount.Text,out amnt);
50


51
                    SFDCCustom.Expenditure__c c = myBinding.createExpenditure(amnt, txtExpName.Text, cboPaidBy.SelectedItem.ToString());
52
                    MessageBox.Show("Record Added Succesfully to salesforce");

53
                    #endregion
54
                }

55
                catch (Exception e1)
56
                {

57
                    MessageBox.Show(e1.Message);
58
                }

59
            }
60
        }

61

62
        private bool login()

63
        {
64
            try

65
            {
66
                binding = new SforceService();

67
                binding.Timeout = 6000;
68
                lr = binding.login(txtUserName.Text, txtPwd.Text);

69
                return true;
70
            }

71
            catch (SoapException e)
72
            {

73
                MessageBox.Show(e.Message);
74
            }

75
            return false;
76
        }

77

78
        private bool validateControls()

79
        {
80
            if (txtPwd.Text.Trim() == string.Empty && txtUserName.Text.Trim() == string.Empty)

81
            {
82
                MessageBox.Show("Please provide the credentials");

83
                return false;
84
            }

85
            return true;
86
        }

87
    }
88
}
Note:
·         To login into application, use the Enterprise WSDL and after that use custom WSDL (That’s why we have two objects of the binding).
·         After login update “SessionHeaderValue” by the custom WSDL sessionHeader.
·         After setting the session header, change the URL of the binding object.
Assumption:
In drop down list, the names of the person added must be available in Salesforce, so that the SOQL to find the person object should return the value.

3..Consume Salesforce Web service in C# .Net Application

In this example, we are going to consume the enterprise WSDL of the Salesforce in C# application.
Log into the Salesforce and navigate to “Your Name | Setup | App Setup | Develop | API” and select the “Generate Enterprise WSDL”.  Copy the URL, as we will need this in our C# Application.
Now Open Visual Studio (I am using Visual Studio 2010) and create new Windows Application. The UI of the application should look like:
C# Application to consume salesforce webservice
C# Application to consume salesforce webservice
Right click on the “References” folder and select “Add Service Reference”.
Add Service Reference in C#
Add Service Reference in C#
Now select the “Advanced” and then select “Add Web Reference…
Provide the URL of the generated WSDL, which we have discussed above in this tutorial.
It will prompt you for the username and password of salesforce, so provide it. After validation, it will display you below screen. Provide “ the web reference name” which will be used in program. In this case, the web reference name is “SFDC_Enterprise_WSDL”.
Add Web reference in C#
Add Web reference in C#
Add the following code in c# application:
1
using System;
2
using System.Collections.Generic;

3
using System.ComponentModel;
4
using System.Data;

5
using System.Drawing;
6
using System.Linq;

7
using System.Text;
8
using System.Windows.Forms;

9
using System.Web.Services.Protocols;
10
using SFDCWebServiceExample.SFDCCustom;

11
using SFDCWebServiceExample.SFDC_Enterprise_WSDL;
12


13
namespace SFDCWebServiceExample
14
{

15
    public partial class Form1 : Form
16
    {

17
        private SforceService binding;
18
        private LoginResult lr;

19
        private SaveExpenditureWebServiceService myBinding = newSaveExpenditureWebServiceService();
20


21
        public Form1()
22
        {

23
            InitializeComponent();
24
        }

25

26
        private void btnLogin_Click(object sender, EventArgs e)

27
        {
28


29
            if (login())
30
            {

31
                describeGlobal();
32
            }

33
        }
34


35
        private bool login()
36
        {

37
            try
38
            {

39
                binding = new SforceService();
40
                binding.Timeout = 6000;

41
                lr = binding.login(txtUserName.Text, txtPwd.Text);
42
                return true;

43
            }
44
            catch (SoapException e)

45
            {
46
                MessageBox.Show(e.Message);

47
            }
48
            return false;

49
        }
50
        private void describeGlobal()

51
        {
52
            binding.Url = lr.serverUrl;

53
            #region[Consume Enterprise webservice]
54


55
            binding.SessionHeaderValue = newSFDC_Enterprise_WSDL.SessionHeader();
56
            binding.SessionHeaderValue.sessionId = lr.sessionId;

57
            #endregion
58


59
            //describeGlobal returns an array of object results that
60
            //includes the object names that are available to the logged-in user

61

62
            DescribeGlobalResult dgr = binding.describeGlobal();

63

64
            //Loop through the array echoing the object names to the console

65
            StringBuilder sb = new StringBuilder();
66
            for (int i = 0; i < dgr.sobjects.Length; i++)

67
            {
68
                sb.Append(dgr.sobjects[i].name+" , ");

69
            }
70
            MessageBox.Show(sb.ToString());

71
        }
72
   }

73
}
Note :
After Successful login, set the “SessionHeaderValue” and “SessionHeaderValue.sessionId”, In this program, we are displaying the comma separated name of all the available objects available to logged in user.
You can download the source code in next tutorial.
In Next tutorial we will discuss on creating the custom web service in salesforce and consuming it in .Net application using c#.


4..Where are the reports for my custom object with related objects in salesforce?

Very often  it is observed that after creating the custom object which is related to other object, developers get surprise that where is the report option for my object with that custom object.
When creating a custom object, you can use the “Relationships” section to define relationships between this new object and other objects. For example let’s say you have a new object called “Expense” that you want to attach to an “Account“.
When you check the “enable reports” box and you go to the report wizard where you choose the type of data you want to report on,  after the standard sections like “Accounts &Contacts”,  ”Opportunities”,  ”Administrative Reports”  you’ll see a new section for “Other Reports”. When you choose that section you’ll see an “Expenses” report type only.
However, if you want to see a report linking “Expenses with Accounts” see below:
1.       Ensure that the relationship between accounts and expenses is a master-detail relationship.
2.       Look for the “Accounts with Expenses” report in the Accounts & Contacts section, not the “Other Reports” section because Account is the Parent object.
Lets take the example of our previously created application of the “Student and Courses“, in which course is the parent object.
As the parent object is not the standard object, in this case the report will be in the “Other reports” section as shown in below image.
Report of custom object with related object in Salesforce
Report of custom object with related object in Salesforce
Hi hope, this article will help to find the cause and solution that where is the custom objects report in salesforce.



5..Difference in Master-Detail relationship and look up relationship – Salesforce Interview question

One important question may asked in Salesforce interview is that what is difference in Master – Detail Relationship and Lookup relationship Fields.

Master detail and look up relationship Salesforce

Master – Detail Relationship :
1.       We cannot create master – detail relationship type fields directly if records already exists.Instead we have to first create Look up fields then fill all the records with that lookup filed. After that we can convert the lookup fields to master – detail relationship.
2.       If we delete master records then detail (Child) records are deleted.
3.       It creates the parent(master) child(Detail) relationship between objects.
Look up relationship :
1.       Look up relationship creates relations between two objects.
2.       If we delete any object then other object is not deleted.
NOTE : The field conversion can only done between master detail relationship and look up relationship, both controls type can interchanged by them only.

 

 

 

 

6..Life Cycle of Visualforce page during GET Request- Salesforce Interview question

Visual force Life cycle Salesforce

 

In the diagram above the user initially requests a page, either by entering a URL or clicking a link or button.This initial page request is called the get request.
1.       The constructor methods on the associated custom controller or controller extension classes are called, instantiating the controller objects.
2.       If the page contains any custom components, they are created and the constructor methods on any associated custom controllers or controller extensions are executed. If attributes are set on the custom component using expressions, the expressions are evaluated after the constructors are evaluated.
3.       The page then executes any assignTo attributes on any custom components on the page. After the assignTo methods are executed, expressions are evaluated, the action attribute on the<apex:page> component is evaluated, and all other method calls, such as getting or setting a property value, are made.
4.       If the page contains an <apex:form> component, all of the information necessary to maintain the state of the database between page requests is saved as an encrypted view state. The view state is updated whenever the page is updated.
5.       The resulting HTML is sent to the browser. If there are any client-side technologies on the page, such as JavaScript, the browser executes them.
As the user interacts with the page, the page contacts the controller objects as required to execute action, getter, and setter methods.
Once a new get request is made by the user, the view state and controller objects are deleted.
Note: If the user is redirected to a page that uses the same controller and the same or a proper subset of controller extensions, a postback request is made. When a postback request is made, the view state is maintained.

 

7,,Schedule export backup of your Salesforce Data – Interview Question

Salesforce allows you to obtain a copy of all your data using the data export feature.  You can generate backup files manually once every six days or schedule them to generate automatically at weekly or monthly intervals.  The backup file will come to you in the form a zip file that contains all of your organization’s data in a set of CSV (comma-separated values) files.  If you do not see the data export feature, contact salesforce.com to have the Data Export Service activated.
Salesforce
Step by Step Instruction:
1.       Click Setup >Data Management > Data Export > Schedule Export.
2.       Select the desired encoding for your export file. Leaving the default is fine.
3.       Check the Include in export checkbox if you want to include attachments in the export (optional)
4.       Leave the default Replace carriage returns with spaces if you want your export files to have spaces instead of carriage returns.
5.       Select Weekly as the the frequency for the exports.
6.       Choose start and end dates. Set the end date to sometime in the distant future such as 20 years from the begin date.
7.       Set the time of day for your scheduled export. The export is put in a job queue and the exact time of the export will depend on the amount of activity in the queue.
8.       You can select the types of data to include in your export. It is best to include all data in your export file. This will make sure all your organizations data is exported.
9.       Click Save.
Points to Remember:
1.       Formula and roll-up summary fields are never included in exports.
2.       Articles are not included from exports.
3.       The export notification email is sent to the email address on file for the user who created the scheduled export. There is no way to indicate another email address. If as an Administrator you want the email to go to another person, have them grant you login access, login as them and schedule the data export.
Important:
1.       Scheduled backup exports of your data is limited to weekly exports.
2.       You have 48 hours from the time you are notifiedthe backup is available to download the backup file.
3.       The email notification for backups goes to the email address in Salesforce of the person logged in who schedules the backup

8..Explain the MVC design pattern of Salesforce.com – Interview Question

Model view controller (MVC) design pattern is the one of the most popular design pattern in 3 tier applications. Salesforce.com is award winning tool to manage all the data of sales team of an organization. The flexibility and assurance of safe data provided by Salesforce.com results into nonparallel development capabilities to the developer. One normal questions asked in salesforce is explaining the MVC behavior of the application.

Salesforce Model view controller (MVC)

So lets discuss that how Salesforce.com uses MVC pattern.
MVC pattern contains below three modules:
1.       Model
2.       View
3.       Controller
Model : What schema and data does salesforce uses to represent the system completely.  In salesforce, we can say that sObjects are the model as every entity in salesforce is mapped to some sObject.
View : How the schema and data is represented. Visualforce is used to present the data to users.
Controller : How the interface actions. Controllers are used to perform the actions whenever users interact with visual force.

9..One visualforce page as an iframe in another visualforce page – Salesforce.com

There may be requirement some times to open one visualforce page into existing page as an iframe.
To achieve this, we can use below lines of code in Visualforce.
<ifram src=”…/MyVFPage?var1= { ! MyVariable1 } &&var2= {  ! MyVariable2 } ” …/>
where { ! MyVariable1 } is custom variable.
to read above parameters in resultant visual force page, we can use:
PageReference pageRef = ApexPages.currentPage();
Map pageMap = pageRef.getParameters();
String var1 = pageMap.get(‘var1‘)

10..Salesforce Tutorial – Create Simple Ajax based Visualforce page

Hello friends,
This time i am going to create very simple AJAX based visual force page for the beginners.
What is AJAX?
As many of you already know that the AJAX stands for the “Asynchronous javascript and XML“.
AJAX is the art of exchanging data between server and client without reloading the complete web page.
Visualforce and AJAX
Visualforce has inbuilt support for the AJAX. using the attribute “rerender” we can specify that where the response should be rendered.
Example:
Lets have an example to demonstrate that how simple AJAX works in visualforce.
Create an APEX class with following code.
1
public class AjaxDemo {
2


3
    private String currTime;
4
    public String getCurrTime()

5
    {
6
        return currTime;

7
    }
8
    public void setCurrTime()

9
    {
10
        currTime = System.now().format('EEEE, MMMM d, yyyy - hh:mm:ss');

11
    }
12
}
As you can see in above Apex class, i have created method named “setCurrTime()” which will set the value of string variable. There is also one get method named as “getCurrTime()” which returns the value of that variable.
On the basis of above Apex class lets create Visualforce page with below code.
1
<apex:page Controller="AjaxDemo">
2
<apex:pageBlock Title="Ajax Sample">

3
Hello <b> {!$User.FirstName}</b>.
4
<apex:form >

5
<br /><br />
6
<apex:commandbutton action="{!setCurrTime}" rerender="ajaxresult"value="Display Current Time" />

7

8
</apex:form>

9
</apex:pageBlock>
10


11
<apex:pageBlock title="AjaxData">
12
  <apex:outputPanel id="ajaxresult" layout="block">

13
    Result: {!CurrTime}
14
  </apex:outputPanel>

15
</apex:pageBlock>
16


17
</apex:page>
There are few points to observe from above visualforce page
·         Apex class earlier created is referenced using attribute “Controller” of “apex:page” tag.
·         On “apex:commandbutton” we have specified that after clicking on button which method of the class should be called using attribute “action“.
·         After the action completion of commandbutton which part of the apex page should gets refreshed is specified by attribute “rerender“.
·         in outputpanel i have specified that which method should gets executed to get the result by simply giving the method name. In this case its {!CurrTime}
Output would look like:
Simple AJAX demo in salesforce using visualforce
Simple AJAX demo in salesforce using visualforce

 

 

11,,How to Host S-Control in Visualforce Page

In order to host your s-control in your Visual Force Pages you need to the the following steps:
1.       Create a new VF page or go to your existing VF page editor
2.       Pick your S-Control API name and have it ready.
3.       Within the Page block or where you find suitable add an apex:scontrol tab as follows:

Visual force page in Salesforce.com
1
<apex:scontrol controlName="Google_Map" width="-100"height="415"></apex:scontrol>

 

 

12..Override standard Links with VisualForce pages in Salesforce

overriding existing salesforce page with your own page is one of the advantages offered by salesforce.com. In this article i will demonstrate that how we can override existing Contact page with our custom contact page.
Go to Set up | Develop | Pages and create new Visual force page with below code.
1
<apex:page standardController="Contact" tabStyle="Lead">
2
<apex:pageBlock title="My Contact Details">

3
<p>Hello {!contact.FirstName}</p><br>
4
<i>Developed by : <b>Jitendra Zaa </b></i></br><br>

5
<i>This is the customPage developed</i></br>
6
<apex:form >

7
<apex:inputField value="{!contact.addit__c}"/>
8
</apex:form>

9
</apex:pageBlock>
10
<apex:detail relatedList="false" />

11
</apex:page>
The above code will only display one textbox (Custom textbox field created by me).
Now go to Set Up | App Set Up | Contacts | Buttons And Links

Salesforce Override Buttons and Links
Salesforce Override Buttons and Links
Edit “View” Button and select your page as shown in below image.

Select Custom Page to override default behavior in Salesforce
Select Custom Page to override default behavior in Salesforce
When you will go to contact page, following output will be visible.

Overriding default button and link in Salesforce
Overriding default button and link in Salesforce
As you can see, we have changed the default User interface of the Contact Page.
For any suggestion please leave your valuable comments.

13..Passing multiple Parameters in ActionFunction in Visualforce

Calling Apex Method from the Visualforce page is the one of the most required functionality in application development in Salesforce. <apex:actionFunction> is one of the method used to achieve this functionality.
Most often we need to supply the arguments in <apex:actionFunction> and in this article I will demonstrate the way in which we can pass one or more than one parameter.
The output of the example will be like below screen.
Passing Parameter in ActionFunction in Visualforce
Passing Parameter in ActionFunction in Visualforce
Create Apex class with following code:
1
public with sharing class PassParameterActionFunction {
2
    public String val{get;set;}

3
    public String enteredText1{get;set;}
4
    public String enteredText2{get;set;}

5

6
    public void echoVal()

7
    {
8
     val = 'You have entered : 1 - '+enteredText1+' 2 -'+enteredText2;

9
    }
10
}
In above code, the variables “enteredText1” and “enteredText2” will be the parameters supplied by the javascript and variable “val” will display the concatenated result.
Now create the Visualforce page with code:
1
<apex:page controller="PassParameterActionFunction">
2
<style type="text/css">

3
.pointer
4
{

5
    cursor:pointer;
6
    border:1px solid #ccc;

7
    padding:5px;
8
}

9
</style>
10
<apex:form id="frm">

11
<apex:outputPanel id="resultPanel">
12
<apex:actionStatus startText="requesting..." stopText="" id="myStatus" />

13
<br />
14
<b><apex:outputLabel value="{!val}" /></b>

15
</apex:outputPanel>
16
<br />

17
Enter Value 1 :
18
<apex:inputText id="txt1" />

19
<br />
20
Enter Value 2 :

21
<apex:inputText id="txt2" />
22
<br />

23
<br />
24
<br />

25
<span class="pointer" onclick="callActionMethod()"> Click Me !!! </span>
26


27
<apex:actionFunction name="echo" action="{!echoVal}" reRender="resultPanel"status="myStatus">
28
<apex:param name="firstParam" assignTo="{!enteredText1}" value="" />

29
<apex:param name="secondParam" assignTo="{!enteredText2}" value="" />
30
</apex:actionFunction>

31
</apex:form>
32
<script type="text/javascript">

33
function callActionMethod()
34
{

35
 var txtVal1 = document.getElementById("{!$Component.frm.txt1}").value;
36
 var txtVal2 = document.getElementById("{!$Component.frm.txt2}").value;

37
 /*Below Method is generated by "apex:actionFunction" which will call Apex Method "echoVal" */
38
 echo(txtVal1,txtVal2);

39
}
40
</script>

41

42
</apex:page>
The below code snippet is used to define the “actionFunction” in visual force page.
To supply the parameter, we have to use “apex:param” tag. Attribute “assignTo” will assign the parameter to variable name specified in Apex code. Here we have assigned the value to variable “enteredText1” and “enteredText2”.
1
<apex:actionFunction name="echo" action="{!echoVal}" reRender="resultPanel"status="myStatus">
2
<apex:param name="firstParam" assignTo="{!enteredText1}" value="" />

3
<apex:param name="secondParam" assignTo="{!enteredText2}" value="" />
4
</apex:actionFunction>
The resulting JavaScript function created by the visualforce will be “echo” because we have set that name for the “apex:actionFunction”.
Attribute “action” will call the method specified on Apex class and “status” will show the Ajax request status.
Below JavaScript method is used to call the generated method by “apex:actionFunction”.
1
function callActionMethod()
2
{

3
 var txtVal1 = document.getElementById("{!$Component.frm.txt1}").value;
4
 var txtVal2 = document.getElementById("{!$Component.frm.txt2}").value;

5
 /*Below Method is generated by "apex:actionFunction" which will call Apex Method "echoVal" */
6
 echo(txtVal1,txtVal2);

7
}
As you can see that we have called the method “echo” with two arguments, because in “apex:actionFunction” we have specified the parameters for the method.

Method 2:
In this method, instead of creating two temporary variable in Apex page and assigning it using attribute “assignTo“ of we can directly get the value in Apex code by something like using
1
Apexpages.currentPage().getParameters().get('paramName');
So the resultant Apex code will be:
1
public with sharing class PassParameterActionFunction {
2
    public String val{get;set;}

3

4
    public void echoVal()

5
    {
6
     val = 'You have entered : 1 - '+Apexpages.currentPage().getParameters().get('firstParam')+' 2 -'+Apexpages.currentPage().getParameters().get('secondParam');

7
    }
8
}
Visualforce code:
1
<apex:page controller="PassParameterActionFunction">
2
<style type="text/css">

3
.pointer
4
{

5
    cursor:pointer;
6
    border:1px solid #ccc;

7
    padding:5px;
8
}

9
</style>
10
<apex:form id="frm">

11
<apex:outputPanel id="resultPanel">
12
<apex:actionStatus startText="requesting..." stopText="" id="myStatus" />

13
<br />
14
<b><apex:outputLabel value="{!val}" /></b>

15
</apex:outputPanel>
16
<br />

17
Enter Value 1 :
18
<apex:inputText id="txt1" />

19
<br />
20
Enter Value 2 :

21
<apex:inputText id="txt2" />
22
<br />

23
<br />
24
<br />

25
<span class="pointer" onclick="callActionMethod()"> Click Me !!! </span>
26


27
<apex:actionFunction name="echo" action="{!echoVal}" reRender="resultPanel"status="myStatus">
28
<apex:param name="firstParam"  value="" />

29
<apex:param name="secondParam"  value="" />
30
</apex:actionFunction>

31
</apex:form>
32
<script type="text/javascript">

33
function callActionMethod()
34
{

35
 var txtVal1 = document.getElementById("{!$Component.frm.txt1}").value;
36
 var txtVal2 = document.getElementById("{!$Component.frm.txt2}").value;

37
 /*Below Method is generated by "apex:actionFunction" which will call Apex Method "echoVal" */
38
 echo(txtVal1,txtVal2);

39
}
40
</script>

41

42
</apex:page>

14..Get DOM ElementID of the Visualforce components

This article will focus on getting generated dom element Id in Visualforce.
Let’s consider below code snap:
1
<apex:page>
2
<apex:form id="frm">

3
Enter Value 1 :
4
<apex:inputText id="txt1" />

5
</apex:form>
6
</apex:page>
If you want to get the id of “apex:inputText” in javascript like belowCode
1
Var fld =  document.getElementById(‘txt1’);
It will NOT work.
Because its actual id will be something like “
j_id0:frm:txt1”.
To get the Actual id in Visualforce page we have to use below line of code:
1
Var fld =  document.getElementById("{!$Component.txt1}");
As you can see, we have to use below Syntax:

{!$Component.fieldId}