Friday, June 1, 2012

Action tags in Visual force page


Action tags in Visual force page:
   We have two types of action given below:
  • Remote Action- JavaScript in VF page call server from Button.
  • Action tags-This tags support for calling action and refresh the field only not visualforce page.
Given below are the different action tags:

  1. apex:actionFunction-
    Provides support for invoking controller action methods directly from JavaScript code using an AJAX request. An <apex:actionFunction> component must be a child of an <apex:form> component.

  1. apex:actionPoller
     A timer that sends an AJAX update request to the server according to a time interval that you specify. Update request can then result in a full or partial page update. You should avoid using this component with enhanced lists.

  1. apex:actionRegion
       This action tag is use AJAX request for particular field or component. Like we have change the value of pick list in visual force then request go to Server and come back through AJAX without Saving the VF page.

  1. apex:actionStatus
          A component that displays the status of an AJAX update request. An AJAX request can either be in progress or complete

  1. apex:actionSupport
     Adds AJAX support to another component, allowing the component to be refreshed asynchronously by server when a particular event occurs, such as a button click or mouse over.

Google Charts in Visualforce Page


Google Charts in Visualforce Page:
   
     We have requirement populate the Charts in Salesforce by counting account type.  Google provides the online editor for creating charts and just pass our values/dimensions.
  We have written apex controller class which gets count of Account type and passing these values to Google API’s chart URL. Google gives us chart image then we populate in to Visualforce.
    We can create charts from Google site editor http://code.google.com/apis/chart/image/docs/chart_wizard.html

   As given below VF page code and apex class have example of chart.

VF page code:
<apex:page controller="googleChartController" tabStyle="Account">
<apex:sectionHeader title=" Type of Account"></apex:sectionHeader>
<apex:image url="{!chartData}"></apex:image>
</apex:page>


Controller class code:
public class googleChartController {
private String chartData;

public String getChartData()
{
 return chartData;
}
//Contructor
public googleChartController ()
{
 //get obtain a list of picklist values
 Schema.DescribeFieldResult F = Account.Type.getDescribe();
 List<Schema.PicklistEntry> P = F.getPicklistValues();
 //where chart data should be stored.
 List<ChartDataItem> items = new List<ChartDataItem>();

 //iterate through each picklist value and get number of accounts
 // I wish we could do GROUP BY in SOQL!
 for(Schema.PicklistEntry pValue : P)
 {
    integer Count = [select count() from Account where Type = :pValue.getValue() limit 10000];
    if (Count > 0)
      items.add(new ChartDataItem(pValue.getValue()+ '-['+ Count.format() + ']' , Count.format()));
 }
 //Prepare the chart URL
 String chartPath = 'http://chart.apis.google.com/chart?chs=600x200&cht=p3';
 chartData = chartPath +  getChartData(items);
}

private String getChartData(List<ChartDataItem> items)
{
 String chd = ''; //23,34,56
 String chl = ''; //Hello|World

 for(ChartDataItem citem : items)
 {
    chd += citem.ItemValue + ',';
    chl += citem.Label + '|';
 }
 //remove the last comma or pipe
 chd = chd.substring(0, chd.length() -1);
 chl = chl.substring(0, chl.length() -1);

 String result = '&chd=t:' + chd + '&chl=' + chl;
 return result;
}// end of method

public class ChartDataItem
{
 public String ItemValue {  get;  set; }
 public String Label {   get;   set; }
 public ChartDataItem(String Label, String Value)
 {
    this.Label = Label;
    this.ItemValue = Value;
  }
 }
}// end of class

Field Set in Salesforce


Field Set in Salesforce:
     Field set is a grouping of fields. You can use Dynamic bindings to display field sets in VF page. For example we have created Field Set on Contact object and add Account Name, First Name, Last etc. Then we can use in VF page.

*Note: Field Set is available for VF pages on API version 21.0 or above.
How to create Field Set?
Go to Set Up>Select Object>Click on Field Set
Enter:  Field Set Label>--------- (Write Field set label)
           Field Set Name>--------- (same as Label)
           Where is this used? ------ (Description)
   Click on Save>
  Click on Edit> Page Layout open

1. Available for the Field Set: A list of fields available for this Field Set. The fields can be moved into the Field Set and rendered on a Visualforce page. Administrators can display the field after the field set is deployed by moving it from the Available column to the In the Field Set column.
2. In the Field Set: A list of fields that are in the Field Set and rendered on the Visualforce page. This is contains field names e.g Account Name, First Name, etc. upto 50 fields.

Drag and drop fields in ‘In the Field Set’.         
Click on Save.

Apex Page:
<apex:page standardController="Contact">
<apex:pageBlock title="Fields in Proper Names">
<apex:pageBlockTable value="{!$ObjectType.Contact.FieldSets.properNames}" var="f">

<apex:column value="{!f}">
<apex:facet name="header">Name</apex:facet>
</apex:column>

<apex:column value="{!f.Label}">
<apex:facet name="header">Label</apex:facet>
</apex:column>

<apex:column value="{!f.Type}" >
<apex:facet name="header">Data Type</apex:facet>
</apex:column>

 <apex:column value="{!f.DBRequired}">
<apex:facet name="header">DBRequired</apex:facet>
</apex:column>

<apex:column value="{!f.FieldPath}">
<apex:facet name="header">FieldPath</apex:facet>
</apex:column>

</apex:pageBlockTable>
</apex:pageBlock>
</apex:page>

How to Add VisualForce page in Standard Page Layout


Requirement: We have requirement when lead saved/created by Partner user then show popup alert message like Lead is saved not submitted.

Technical: Partner portal user creates Lead and Save it so it will open Lead standard page. So we need to add Alert message on this Standard page. We have two options given below:
Open 1: We can override the Lead’s View which is in
Setup>Object (Lead)>Standard Button and Link>View>Edit
First you have to create visualforce page which is getting the window on load alert message. Add this page to View override in Lead.

Open 2: We have another option like if we have visualforce page and add in to Page Layout. Which checks the Lead Status = ‘Draft’and Lead Category = ‘Opportunity Registration’ then show alert message to Portal user. We have created Visualforce page which satisfy above criteria and show alert message.

Visualforce Page OppRegAlertPage:

<apex:page standardController="Lead" tabStyle="Lead" >
<apex:form >
<apex:inputHidden value="{!Lead.Lead_Category__c}" id="LeadCategoryId"/>
<apex:inputHidden value="{!Lead.Status}" id="StatusId"/>
</apex:form>
<script language="javascript">
  var LdCategory;
  var LdStatus;
      LdCategory=document.getElementById('j_id0:j_id1:LeadCategoryId').value;
      LdStatus=document.getElementById('j_id0:j_id1:StatusId').value;    
   window.onload = function() {
    if( LdCategory == 'Opportunity Registration' && LdStatus =='Draft'){
           alert(‘Lead Saved but not Submitted!');
           }
   }
</script>
</apex:page>

I)   Setting>Go to Lead> Page Layout>Select page layout for Portal user>Edit
II)  Click on Edit Layout> Click on Visualforce pages>Select page > Drag and Drop in to Page
III) section>Double click on Page>
IV) Open Visualforce Page Properties> Width (in pixels or %)s=10%
                                                         Height (in pixels) = 0
                                                         Save Page Layout.

Salesforce.com Interview Question


  1. Difference between Data Load v/s Data Export.
  2. Difference between Master Detail v/s Lookup.
  3. What is the Trigger Oder execution?
  4. What is Force.com?
  5. What are New Release Summer’11 Features?
  6. What is OWD and what is different type of sharing?
  7. What is Apex Governor Limits and how it work and all new rules?
  8. What are Record Type and Page Layout?
  9. What is Trigger Best Practice and how can write SOQL?
  10. Difference between with Sharing v/s without sharing
  11. What is Queue Group?
  12. Difference between External Id and Data Type of Id.
  13. Difference between Standard v/s Custom Controller v/s Extension.
  14. What is Multitenant and Application Server for Salesforce?
  15. What is Trigger context Variable and mode?
  16. Difference between trigger.new v/s trigger.old.
  17. How to use AJAX in Salesforce?
  18. What’s the used of Web service?
  19. What is Field set?
  20. What is SOAP (Simple Object Access Protocol)/
  21. What is Rest API and which are used in Salesforce?
  22. What is Callout=true and where it is used?
  23. What are the apex: insert apex: composition tag?
  24. What us Enum?
  25. What are recursive triggers? How can we avoid the recursion problem?
  26. What are the types of relationship?
  27. Visualforce Action tags like apex:function,support etc?
  28. What is Visualforce template and how can we do? Or insert/composition tag etc
  29. Difference between assignment and escalation rules?
  30. Difference between task and event.
  31. Difference between WhatId and WhoId.
  32. What is change set and difference between Eclipse/Ant tools?
  33. What is the use if Custom Setting?
  34. What Scheduler class and how can use?
  35. Visual force page order execution load/action etc?
  36. Visualforce email template class and test method of this class?
  37. How is Role Different from the Profile?
  38. What are the different ways of making a field mandatory?
  39. What is the difference between Customer Portal and Partner Portal?
  40. What is difference between Workflow and Approval process?
  41. What is used of Roll of summary field and where can we use?
  42. What is actionPoller tag?
  43. What is the difference between a Profile and Role?
  44. What are wrapper classes in salesforce.com?
  45. What is batch apex and Salesforce limitation for this batch?
  46. How can we write Webservice for Salesforce?
  47. Difference between HTTP and HTTPS request and response?
  48. What are global variables and how can use in VF page?
  49. What is jQuery and how can use in VF page?
  50. What will happen if the Account is deleted? 
  51. What is transient and where we can use in salesforce?
  52. Difference between final/instance of/super/this keywords?
  53. What is annotation (@) and type of annotation like Deprecated/Future/is Test/ Remote Action etc and difference?
  54. Difference between List/Set and Map and uses?
  55. Difference between SOQL and SOSL and uses?
  56. Difference between Enterprise and Partner WSDL?
  57. What is site in salesforce and where can we use?
  58.  How can call Apex controller class from visualforce page without command button?
  59. What is ifram tag and how can we use?
  60. What apex:insert tag and how can we used?
  61. What is Action class and where we can use?
  62. Difference between Custom List Buttons using Standard List Controllers?
  63. How can use time based workflow and how can use outbound messages?
  64. Difference between Debug Log/System Log etc.
  65. What is Queue and how can we use in salesforce?