Author Archives: Biswajeet

About Biswajeet

Biswajeet is my Name, Success is my Aim and Challenge is my Game. Risk & Riding is my Passion and Hard Work is my Occupation. Love is my Friend, Perfection is my Habit and Smartness is my Style. Smiling is my Hobby, Politeness is my Policy and Confidence is my Power.

Populate Picklist from Custom Object to the Visualforce Page


public with sharing class Sample
    public string selectedValue {get; set;}
    public List<SelectOption> industry {get; set;}
    public void getIndustry()
        Schema.DescribeFieldResult industryDescription = Account.Industry.getDescribe();
        industry = new List<SelectOption>();
        for (Schema.Picklistentry pl : industryDescription.getPicklistValues())
            industry.add(new SelectOption(pl.getValue(),pl.getLabel()));
    public void checkValue()
        System.debug('Selected Industry Type - ' + selectedValue);

Visualforce Page:

<apex:page controller="Sample" action="{!getIndustry}" sidebar="false" showHeader="false">
    <apex:form >
            <apex:pageBlockSection columns="1" >
                <apex:outputLabel value="Industry Type" />
                <apex:selectList size="1" value="{!SelectedValue}" >
                    <apex:selectOptions value="{!industry}"/>
                    <apex:actionSupport event="onchange" action="{!checkValue}" />


Calculate # of Months between a Start and End Date Formula in Salesforce

YEAR(End_Date__c) = YEAR(Begin_Date__c),
MONTH(End_Date__c) = MONTH(Begin_Date__c)),
(YEAR(End_Date__c)*12+MONTH(End_Date__c)) –

Difference Between Clone and DeepClone in Apex in Salesforce

Clone Deep Clone
Generally clone the list of object and keep the reference. Generally it clone the list of object but don’t hold any reference.
A Clone doesn’t keep the Ids. A Deep Clone keeps the Id.
Supports primitive data type. Doesn’t support primitive datatype.
Parameters are not applicable. Parameter are applicable.

Here is a an example to understand difference between Clone and DeepClone:
I am creating a New Account with some fields.

Account acc = new account(Name = 'Salesforce', Billingcity = 'San Francisco', Type = 'Customer - Direct', Phone = '9999999999');
insert acc;

This creates a record in the Account as shown below:

Now, I am cloning it and inserting again.

Account acc = new account(Name = 'Salesforce', Billingcity = 'San Francisco', Type = 'Customer - Direct', Phone = '9999999999');
insert acc;

//Cloning the above Account Record acc
Account accCloneCopy  = acc.clone(false, false, false, false);
insert accCloneCopy;

It creates a new copy of the record with same values, since it keeps the reference, new record ID is generated for cloned record.

Now, when I try to deepclone the record: (Deepclone is done by keeping true in the parameters) like,
clone(preserveId, isDeepClone, preserveReadonlyTimestamps, preserveAutonumber)

Account acc = new account(Name = 'Salesforce', Billingcity = 'San Francisco', Type = 'Customer - Direct', Phone = '9999999999');
insert acc;

//Deep cloning the above record
Account accDeepCloneCopy  = acc.clone(true, true, false, false);
insert accDeepCloneCopy;

It shows an error, because the Id is also considered and cannot insert the deppcloned record:

Test Class for Batch Apex in Salesforce

Batch Class:

global class BatchAccount implements Database.Batchable<sObject> 
    global Database.QueryLocator start(Database.BatchableContext BC) {
        return Database.getQueryLocator('SELECT Id,Name FROM Account');
    global void execute(Database.BatchableContext BC, List<Account> scope) {
        for(Account a : scope)
            a.Name = a.Name + ' Updated';
        update scope;
    global void finish(Database.BatchableContext BC) {

Test Class:

public class BatchAccountTest 
    static testMethod void test() 
        List<Account> accList = new List<Account>();
        for(Integer i = 0 ; i < 200; i++)
            Account acc = new Account();
            acc.Name = 'Name' + i;
        Insert accList;
		BatchAccount obj = new BatchAccount();
		//Verify accounts updated
		List<Account> accUpdatedList = [SELECT Id, Name FROM Account];