Managing session time out at profile level

Session settings at profile level – Winter 15 update




Now you can manage session timeout at profile level. Salesforce has provided this option in their winter 15 release. Earlier (before winter 15) we had only option to set this change at organization level. But in winter 15, you can manage session timeout at profile level. profile level changes override the organization session settings. Until you set this on a profile, the organization-wide Timeout value in the settings applies to users of the profile. Once set, the this on a profile overrides the organization-wide Timeout value for users of that profile. Changes to the organization-wide Timeout value will not apply to users of a profile with its own Session Timeout value.



where we can find these settings at org level? To find these settings at org level go to setup ->Administer-> Security controls. here you will find timeout option. See the below screen for reference.

session timeout

Where we can find these settings at profile level?

Go to setup -> administer-> Manage Users -> profile -> edit -> go to session settings & change time out value for profile. see below screen for reference.

Session Time Out At Profile Level

This option will really helpful for administrators to manage session settings at profile level.





actionpoller tag in salesforce

actionPoller




What is actionPoller tag? This tag specifies a timer that sends an AJAX update request at specified interval. Minimum interval time to refresh is 5 sec.

Here in this post i am providing a simple example to explain about actionPoller.  I am calling a simple method from controller to display Date & TIme and recalling that method by using actionPoller tag to change the time for every 5 sesc. See the below code to understand how actionPoller will work.



Visualforce page Code:

<apex:page controller="actionpollerDemoController">
    <apex:form >
        <apex:pageBlock id="pb">
             <apex:actionPoller action="{!dateTimeMethod}" reRender="pb" interval="5"/>
                     Hello!!!  Date and Time: {!dateAndTime} 
                     <p>Note: Time will refresh fror eevry 5 sec.</p>
         </apex:pageBlock>
      </apex:form>
</apex:page>

Apex Controller:

Public with sharing class actionpollerDemoController {

Public DateTime dateAndTime{get;set;}

Public void dateTimeMethod(){
dateAndTime = System.now();
}
}

OutPut: In below screen rounded part will refresh for every 5 secs

ActionPoller

Know more about this tag





actionFunction tag in visualforce

actionFunction




What is <apex:actionFunction> tag? This tag defines  JavaScript functions to be called from JavaScript code.  By using this tag you can call controllers methods from java script code using an AJAX request .

This component must be a child of <apex:form> tag. And we cannot place this tag inside an iteration tag like <apex:pageBlockTable> & <apex:repet> now. Earlier we were able to do this.But with api version 23 we cannot place <apex:actionFunction> inside iteration tags.



Here I am providing an example, How to use <apex:actionFunction> tag is visualforce. I have created simple Lead form to enter lead details from custom page. Last name, Company & email are mandatory fields in below page. If any miss those required fields, I am displaying  alert by Javascript and i am calling method from java script to save the record. See below code to understand, how <apex:actionFunction> will work.

Visualforce page code:

<apex:page controller="InsertLeadController" showHeader="false">

<script type="text/javascript">
function validate()
    {
        if(document.getElementById('{!$Component.LF.LDB.Lname}').value == '' || document.getElementById('{!$Component.LF.LDB.comp}').value == '')
        {
            alert("LAST NMAE & Company are requird fields");
        }
        
        else
        {
            CallsubmitLead();
            alert("Account has been inserted");
        }
    }
    
 </script>
    
 <apex:form id="LF">
 <apex:actionFunction action="{!submitLead}" name="CallsubmitLead" reRender="LDB"/>  
 <apex:pageBlock title="Lead Form - Enter lead details" id="LDB"> 
  <table>
  <tr>
  <td><apex:outputText value="First Name"/></td>
  <td><apex:inputText value="{!firstName}"/></td>
  </tr>  
  <tr>
  <td><apex:outputText value="Last Name"/></td>
  <td><apex:inputText value="{!lastName}" id="Lname"/></td>
  </tr>  
  <tr>
  <td><apex:outputText value="Comapany"/></td>
  <td><apex:inputText value="{!comapany}" id="comp"/></td>
  </tr>  
  <tr>
  <td><apex:outputText value="Mobile"/></td>
  <td><apex:inputText value="{!mobile}"/></td>
  </tr>  
  <tr>
  <td><apex:outputText value="Lead Status"/></td>
  <td><apex:selectList value="{!statusOptions}">
  <apex:selectOptions value="{!items}"/>
  </apex:selectList></td>
  </tr>
  </table>  
  <apex:commandButton value="Save" onclick="validate();"/> 
 </apex:pageBlock>  
  </apex:form>
</apex:page>

Controller Code:

public class InsertLeadController {

public String statusOptions { get; set; }
public String comapany { get; set; }
public String mobile { get; set; }
public String firstName{get;set;}
public String lastName{get;set;}
public Lead l = new Lead();

public List<SelectOption> getItems() {

List<SelectOption> options = new List<SelectOption>();
options.add(new SelectOption(‘Open – Not Contacted’,’Open – Not Contacted’));
options.add(new SelectOption(‘Working – Contacted’,’Working – Contacted’));
options.add(new SelectOption(‘Closed – Converted’,’Closed – Converted’));
options.add(new SelectOption(‘Closed – Not Converted’,’Closed – Not Converted’));
return options;
}

public PageReference submitLead() {

l.FirstName=firstName;
l.LastName=lastName;
l.Company=comapany;
l.MobilePhone=mobile;
l.Status=statusOptions;
insert l;
return null;
}
}

In this example, I am calling submitLead methods from javascript.





Quick Deployments in salesforce

Quick Deploy –  Deployments in less time




What is quick deploy? By using this option you can deploy components to production with running test classes on your project release day. But you have to do successful validation before your release day.

Generally in salesforce deploying code to production very hard when your organization contain more test methods. If your organization contain more test methods, then your release will very long. But to avoid this, salesforce has provided quick deploy option. By using this option you can deploy code to production in very less time on your project release day.



This quick deployment option is only available for production environments. This not doesn’t applicable for non production organization & deployments not required for apex tests.

Salesforce has released this as a pilot program. If you want to enable this option for your org, then you you need to contact salesforce.com.

See below screen to under stand quick deployment option.

Quick Deployment

 If you did a successful validation of your package, then you can deploy that same deployment without running any test classes to your production. This option is valid for 4 days (96 hours) for successful validated deployment. Quick deployments are available only for validations with test runs that have passed  in the last four days.





Now we can do deployments with Active job

Doing deployments when Active job is running




What is active job here? Any schedule job or apex job which is running in our salesforce system.

Generally in salesforce, we cannot perform deployments when active jobs are there & we are trying to deploy metadata related to active job in system. In this case we will remove jobs from our environment and continue with deployments.

But now, no need to stop schedule jobs in our environments to perform deployment when active jobs are running. In winter 15 release salesforce has provided a feature to continue with deployments when jobs are running in production.

Enabling the deployment of components with corresponding   active job.

To enable this go to setup -> deployment  settings -> “Allow deployments of components
when corresponding Apex jobs are pending or in progress” check this check box and save.

Deployment connection is renamed as deployment settings. See the below image for reference.

Deployment settings - active jobs

Active jobs

I feel this is very useful option when are doing deployments. No need to stop jobs during deployments. But, this setting might cause apex jobs fail due to unsupported changes.





Custom Controllers & Controller Extensions

Custom Controllers




What is custom controller? why we go for custom controllers?

Standard controllers provides only built in standard functionality to visualforce pages, such as Save, Edit, Cancel & Delete etc….

We cannot customize/develop our own functionality by using standard controllers. By using custom controllers we can write our own functionality or override existing functionality. Custom controller is an Apex Class developed by us. See the below syntax to define custom controller in visualforce page.

<apex:page Controller=”ControllerName”>

 What is controller extension? Controller extension is custom/additional behavior to standard controllers. Extension is an apex class. We can add number of extensions to visualforce page. See below syntax to define extension.

<apex:page Controller=”ControllerName” extensions=”Class1, Class2,..”>

We can use Stnadard controller/ Custom Controller and extensions at a time. But we cannot use Standard controller & Custom controller at a time. See below syntax to understand.

<apex:page standardController=”ControllerName” extensions=”Class1, Class2,..”> Correct

 <apex:page Controller=”MYControllerName” extensions=”Class1, Class2,..”>   Correct syntax

<apex:page standardController=”MYControllerName” Controller=”MyController”>  Wrong



 What we can do by using Custom Controllers?

– We can override existing functionality

– We can create new functionality.

– We can customize navigation.

– We can use HTTP callouts & Web Services

– We can have control for how information is accessed on the page.

Example to create custom controller:

In this example, I am creating a visualforce page to create & save multiple accounts at a time by using visualforce page & Custom controller.




Code for Visualforce page

<apex:page Controller="AddmultipleAccountsController">
<apex:form >
<apex:pageBlock >
<apex:pageBlockTable value="{!listAccount}" var="acc">
<apex:column headerValue="Account Name">
<apex:inputField value="{!acc.Name}"/>
</apex:column>
<apex:column headerValue="Account Number">
<apex:inputField value="{!acc.AccountNumber}"/>
</apex:column>
<apex:column headerValue="Account Type">
<apex:inputField value="{!acc.Type}"/>
</apex:column>
<apex:column headerValue="Industry">
<apex:inputField value="{!acc.Industry}"/>
</apex:column>
</apex:pageBlockTable>
<apex:pageBlockButtons >
<apex:commandButton value="Add one more account" action="{!addAccount}"/>
<apex:commandButton value="Save Accounts" action="{!saveAccount}"/>
</apex:pageBlockButtons>
</apex:pageBlock>
</apex:form>
</apex:page>

Code for custom controller:

public class AddmultipleAccountsController {
Account account = new Account();
public list<Account> listAccount{ get; set; }

public AddmultipleAccountsController()
{
listAccount=new list<Account>();
listAccount.add(account);
}

Public void addAccount()
{
Account acc = new Account();
listAccount.add(acc);
}
public PageReference saveAccount() {
for(Integer i=0; i<listAccount.size(); i++)
{
insert listAccount;
}
return Page.Allaccountssaved;    // I am returning another vf page here.
}
}

Out put of above code: We can add multiple accounts at a time by using this page like below.




Here I am adding multiple rows and saving all records at time. We cannot achieve this by using standard controller. So i have written custom controller to achieve this.

Custom Controllers




apex:selectList with standard list Controller

What is <apex:SelectList> tag?




Apex:selectList is used to display list options that allows user to select one.more values at a time. See below Syntax to use apex:select list

<apex:selectList size=”1″ value=”{!filterId}”>
<apex:actionSupport event=”onchange” reRender=”oppList”/>
<apex:selectOptions value=”{!listviewoptions}”/>
</apex:selectList>

Know more about selectList

Below is the simple example to display list of records in visualforce page with list view & actions.

<apex:page standardController="Opportunity" recordSetVar="opportunities">
<apex:form >
<apex:pageBlock title="Displaying Opportunities">

<!-- Below <ape:selectList> tag is used to display listview -->

<apex:selectList size="1" value="{!filterId}">
<apex:actionSupport event="onchange" reRender="oppList"/>
<apex:selectOptions value="{!listviewoptions}"/>
</apex:selectList>

<!-- below code displays list of opportunnities -->

<apex:pageBlockTable value="{!opportunities}" var="opp" id="oppList">
<apex:column value="{!opp.Name}"/>
<apex:column value="{!opp.Account.Name}"/>
<apex:column value="{!opp.StageName}"/>
<apex:column value="{!opp.Type}"/>
<apex:column value="{!opp.ExpectedRevenue}"/>
</apex:pageBlockTable>

<!-- Using List action to display first, last, next & previous list -->

<apex:pageBlockButtons location="Bottom">
<apex:commandLink value="First" action="{!First}"/> &nbsp;
<apex:commandLink value="Next" action="{!Next}"/> &nbsp;
<apex:commandLink value="Previous" action="{!Previous}"/> &nbsp;
<apex:commandLink value="Last" action="{!Last}"/>
</apex:pageBlockButtons>
</apex:pageBlock>
</apex:form>
</apex:page>

 




Standard List Controllers

What is Standard List Controllers?




By using standard standard list controllers we can manage set of records. For every standard controller there exists a standard list controller that allows you to create pages that display and act on a set of records, such as list pages, related lists, and mass action pages. We can associate define standard list controller by using recordSetVar.

<apex:page standardController="Account" recordSetVar="accounts">

Standard list controller provides additional four pagination actions. Those are first, last, next and previous.

We can use standard list controllers with the following objects.

Account, Asset, Campaign, Case, Contact, Contract, Idea, Lead, Opportunity, Order, Product2, Solution, User, Custom Objects.

Standard list controller example:

<apex:page standardController="Account" recordSetVar="accounts">
<apex:form >
<apex:pageBlock >
<apex:pageBlockTable value="{!Accounts}" var="a">
<apex:column headerValue="Account Name">
<apex:outputField value="{!a.name}"/>
</apex:column>
</apex:pageBlockTable>

<!-- pagination actions supported by standard list controller -->
<apex:pageBlockButtons >
<apex:commandButton value="First" action="{!first}"/>
<apex:commandButton value="Last" action="{!last}"/>
<apex:commandButton value="Next" action="{!next}"/>
<apex:commandButton value="previous" action="{!previous}"/>
</apex:pageBlockButtons>
</apex:pageBlock>
</apex:form>
</apex:page>





Standard Controllers in Salesforce

Standard Controllers




A StandardController object that is automatically provided for standard and all custom objects, bindable to a Visualforce page component with the “standardController” attribute. It provides a reference to a single/list of record to a set of common actions for data processing and default navigation.

What are the tasks of standard controller?

Standard controllers provides ability to access and interact with structured business data contained in records displays in the proper user interface.




Standard controller tasks: controlling data, controlling actions and controlling navigation.

Controlling Data:

Standard controllers fetches data and provide to the views such as page, list, dialog or forms.

Controlling data for a single record: One of the key functionality of standard controllers is to provide the data, and to facilitate binding a view’s controls to the records fields for either display or input. We can associate a standard controller with a visual force page by using “StandardController”  attribute.

<apex:page standardController=”Account”>                // standard object
<apex:page standardController=”customer__c”>        
// custom object

By using merge expressions we can add fields to visualforce pages. This is the same merge syntax used in email templates, formulas and any place that field values need to be merged for expression evaluation. Below highlighted blue color syntax are merge fields

<apex:outputField value="{!Account.Name}"/>
<apex:outputField value="{!Account.AccountNumber}"/>
<apex:inputField value="{!Account.Industry}"/>
<apex:inputField value="{!Account.Type}"/>

See the below syntax to represent represent related parent object fields.

<apex:inputField value="{!Account.Owner.Name}"/>

We can represent a related list in visualforce page by using below syntax.

<apex:relatedList list="Contacts"/>

To view output, after developing your page , you need to pass related sobject record id with your salesforce url. see below example.

https://c.apX.visual.force.com/apex/vfpage?id=XXXXXXXXXXXXXXX

Controlling data for list of records: 

We can manage list of records by using standard controller instruction set. We can define recordsetVar by using below syntax.

<apex:page standardController="Account" recordSetVar="accounts">

Standard controllers provide below additional actions for list of records.

First: Displays the first page of records in the set.

Second: Displays the last page of records in the set.

Next: Displays the next page of records in the set.

Previous: Displays the previous page of records in the set.

Controlling Actions & Navigation:

Actions: Standard controller responds to to user or programmatic commands initiated from a view such as “buttons & custom links.

There are two types of actions available on objects through standard controllers instruction set.

Stateful Actions: Direct binding to a standard controller instance referenced by the page.

Stateless Actions: Indirect binding to the standard controller instruction set of the force.com engine. 

Navigation: Standard Controllers navigate the user to any specific view associate with an action.