Thursday, January 12, 2017

What is Default Backend formats for Date and DateTime in Salesforce

Today I'm going to share an exiting hidden feature of salesforce. We will be using regularly date and datetime fields in salesforce. I will discuss few points about these fields now.


 I have one datetime field in my object which typically stores the date time .Now I have created one record in that object passing some date and time to that field.Lets assume that the value is 11 Jan 2017 and time as 3Am(03:00:00) .I have successfully created a record and my time zone is IST .
Now I open my developer console and trying to query the same record with the help of datetime(11Jan 2016 3Am) then my query ends up with no result.Why is it ?What happened?

Root Cause:

 Now I have taken some other field(Id or String) from same object to debug actually what happening in the backend and included this datetime field in query.The value for datetime field is showing some thing like 10 Jan 2017 and time as 9pm (21:30:00) but when I added same field to page layout or in visual force page I'm getting the 11 Jan 2017 and time as 3Am(03:00:00) .Then I went through many blogs and docs of salesforce and came to know that by default the Salesforce will stores all Date and Datetime fields in database in the format of Coordinated Universal Time (UTC) which also know as Greenwich Mean Time (GMT) and it will not consider what is the logged in user time zone.


So due to above mentioned statement the converted value of IST 11 Jan 2017 and time as 3Am(03:00:00) will comes as 10 Jan 2017 and time as 9pm (21:30:00) because we are ahead of +5:30 compared to GMT/UTC.

So when you were working with date or datetime fields better you will make sure that you follow all these conversions to get the exact data.

Whenever showing these date or datetime fields in pagelayout or visual force page salesforce automatically converts that GMT/UTC value to logged in user respective timezone so that is the reason we are able to see 11 Jan 2017 and time as 3Am(03:00:00) on layouts and vf pages instead of 10 Jan 2017 and time as 9pm (21:30:00)

Salesforce already provides some internal date and datetime functions to make all these conversions.
We will see more details about all these functions in my next post.

Thanks for visiting..hope this helps you!

Wednesday, January 11, 2017

What is the Default Article Type for Salesforce Knowledge Base

When you enabled Salesforce Knowledge Base in your organisation then the default Article Type given by Salesforce will be Knowledge.

If you want create custom article types based on your Article purpose we can create and link your article for preferred article type.

Thanks for visiting..hope this helps you!

Monday, January 9, 2017

What is the maximum number of Promoted Terms we can create in Salesforce

Promoted Term:

        These are nothing but the terms or words which we will be attaching to knowledge articles to make the smother search of the Articles very quick based on prompted words which matches with given search keywords.

These terms are limited to 2000 for an organisation and for better search results it's better to have less than 2000.

Thanks for visiting..hope this helps you!

Sunday, January 8, 2017

How to declare an Array in Salesforce

An Array is nothing but collection of similar type of data.So we can refer an array is nothing but a list in salesforce. In this example I will show you how to declare an array in salesforce.

Sample declarations

Array without any size:

String[] paramList = new String[]{};
            is similar to
List<String> paramList  = new List<String>();
String[] paramList  = new List<String>();

Array with size:

String[] paramList = new String[8];

Thanks for visiting..hope this helps you!

Wednesday, January 4, 2017

How to pass parameters from JavaScript to Controller in Salesforce

If you want to send more than one parameter from javaScript to Apex controller in your class,no worries it can be done easily .Please follow the below snippet to achieve the same.

Sample VisualForce Page

   <select id="dropDownId"/>
   <apex:commandButton value="Update" onclick="validate();return false;" />
  <apex:actionFunction name="updateRecords" action="{!performUpdate}" 
                              reRender="resultPanel,errMsg" status="statusSaveTrip">
        <apex:param id="status" name="selStatus" value="" />
        <apex:param id="renerTabId" name="renderTabId" value="" />
        <apex:param id="phone" name="phone" value="" /> 

  function validate(dropDownId )
    //Some processing here
  updateRecords(param1 value,param2 value,param3 value);

Sample Apex Controller

public class SampleController
   public SampleController()
   public pagereference performUpdate()
     String selDropdownVal=Apexpages.currentPage().getParameters().get('selStatus');
     String tableIdtoRender = Apexpages.currentPage().getParameters().get('renderTabId');
     String phone = Apexpages.currentPage().getParameters().get('phone');

Thanks for visiting..hope this helps you!

How to add pick list field values dynamically in visual force

If we want to add picklist values at run time in visual force it can be done very easily by using <apex:selectOptions> tag .Their might be a situation where you need to go with html 'select ' tag to form the picklist. In this situations if you want add values to it run time their is no in built attributes as we follows in visual force tags.To achieve this we need to use some scripting .In this example I'm going to show with the help of jQuery.

Sample code snippet:

 <apex:includeScript value="//"/>
  <apex:form id="formId">
   <select id="dropDownId">
   <apex:commandButton value="Update" onclick="addPicklistValues('dropDownId');return false;" rerender="formId"/>

  function addPicklistValues(dropDownId )
  var dropId = '#'+dropDownId;
  $(dropId).find('option').remove().end().append('<option value="-None-">--None--</option>','<option value="Approved">Approved</option>','<option value="Rejected">Rejected</option>');

Thanks for visiting..hope this helps you!

Tuesday, January 3, 2017

Jquery to check that checkbox is selected or not in visual force

If you wanna check whether a checkbox is selected or not in visual force please use the below jQuery snippet.

jQuery code snippet:

 function updateSelRecords(checkboxid or checboxstleclas)
        var chbxClassId = '.'+checboxstleclas; // if your receiving checkbox styleclas
        var chbxClassId = '#'+checkboxid; //if your receiving checboxId
           alert('Checkbox selected');
         alert('Please select at least one record');
           return null;

Thanks for visiting...!

Monday, January 2, 2017

How to select all check boxes in visual force page using Jquery class attribute

If you want to select all records in a table we can do it very simply by using tag name but there are some situations where we have 4 tables and clicking on All check box in one table should select only the records related to that table not the all table records.

To achieve that we need to have a unique identifier for each table record but unfortunately in sales force Id of any vf tag can't be a dynamic so we can't use ID here .There is one more attribute called 'styleclass' in visual force tags which can be a dynamic.Now we are using this class attribute to differentiate the table records and we will use jQuery to achieve this functionality.

Sample code snippet:

<apex:repeat value="{!listSer}" var="sr">
  <apex:pageBlockTable value="{!listWrapCase}" var="caseWrap" id="pgbId">
   <apex:column >
     <apex:facet name="header" >
       <input type="checkbox" onclick="selectAllCheckboxes(this,'{!sr}chbxId')"/>
   <apex:outputPanel >
     <apex:inputCheckbox value="{!caseWrap.isSelect}" styleClass="{!sr}chbxId"/>
  <apex:column >
    <apex:facet name="header" >CaseId</apex:facet> 
    <apex:outputLabel value="{!caseWrap.cs.CaseNumber}" />

Jquery snippet:

<script type="text/javascript">  
      function selectAllCheckboxes(obj,receivedInputclass){

Thank you!


New Year’s marks a new beginning. 
New people to meet, 
new adventures to enjoy 
and new memories to create. 
Here’s wishing you the Happiest New Year ever!

Thank you...have a great year ahead..Enjoy!