Tag Archives: Force.com

Difference between Salesforce external objects and custom objects

Feature Custom Objects External Objects
Data is stored in your Salesforce org Yes No
Read Yes Yes
Write Yes Yes (limited)
Tabs, layouts Yes Yes
Visualforce Yes Yes
Field-level security Yes Yes
Sharing Yes No
SOQL Yes Yes (limited)
Search and SOSL Yes Yes (pass-through)
Formula fields Yes Not Yet
Workflow, triggers Yes Not Yet
Reports and analytics Yes Not Yet
Chatter Yes Yes (no field tracking)

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: