SOQL Datetime literal in javascript for current Datetime.

Sometimes we need to use AJAX toolkit to do some SOQL/DML on Data from a custom button, which executes javascript. Here in this post we will just get current Datetime and then we will create datetime literal as per SOQL standard to fetch some records as per requirement.

For more information about SOQL date/datetime formats Click Here.

Where to Use :

This can be used when you need to fetch records where some datetime field is less/greater than current time. You can also update it to get records of last 1 hours, 2 hours etc.

Datetime Literal Javascript Methods :

Use With Ajax toolkit Salesforce :

Hope this will help when you are creating SOQL query string using javascript.

Use it wherever you can whether its javascript button, lightening component or anything, to save your time and be a speedy coder.

Datetime on Visualforce Page

Whenever we are working with datetime on visualforce page, we may face some issue either with its formatting or its value not coming correctly. So basically the formatting of date depends on the locale of the user, and second thing which is its value depends on the timezone.

In the salesforce database each datetime value is stored in GMT, and when this is shown on the detail page it is adjusted with the current user’s timezone or offset. But sometime we developer create custom visualforce pages to fulfil different different business requirements. Here I come up with the all possible use cases and solution of showing Datetime on visualforce page with their pros and cons.

Datetime on Visualforce Page
  • Datetime Format (Showing DD/MM/YYYY, showing time only, showing year only, showing week day etc).
  • Datetime Value (Either in GMT or in current user timezone).
Method/Approach Taken Is Format Customizable ? Is Current Timezone ?
apex:outputText – direct datetime value. NO NO
apex:outputText – formatted using apex:param. YES NO
apex:outputText – with one space in value(Trick). NO YES
apex:outputText – (Offset is added on page). YES(But in controller) YES
apex:outputText – Showing a String containing formatted Datetime from controller. YES YES
apex:outputText – (Offset is added from controller). YES YES
apex:outputField – (No Customization can be done with format). NO YES
Datetime on visualforce page
Datetime on Visualforce page
Source Code

Visualforce page Code

Apex controller


For Different format see Datetime format Patterns.

So I have shared my finding on the datetime on visualforce page, I hope that this will help developers. Please comment if you need further explanation or have any feedback.

Apex:actionRegion not working with Apex:actionFunction

One of my friend was using apex:inputFile on a Visual force page, and he also needs to reRender some information on the same page. If we need to use both together, we have to use apex:actionRegion in order to isolate apex:inputFile (because inputFile doesn’t support reRender and throws error).

He was also doing the same thing but the state of information was not maintained, See the below psuedo code to get an idea of code

You will think that the above code will work fine, But It won’t!

Issue In the Above Code

Let’s say you are using a list of contact in editable mode where user can add or remove rows and update the information of contact.
User has added one row and filled the information, Now he clicked on some button to add one more row. To add row, function “myFun” (placed in actionRegion 1) is invoked. Here the information for first row of contact will go away on reRender of myInfo panel.

Solution/ Workaround

As of now, after doing some research and hit and trial approach  I have found one workaround or you can say solution. Instead of putting apex:actionFuntion and your part which needs to reRendered put them in a single actionRegion. So the updated code (working) will be as follows.


For now there is no 100% correct explanation behind this behavior. May be actionFunction sends only information of apex:actionRegion in which it is placed to the server. For example if actionFunction is in actionRegion A, then it will send information from actionRegion A to the server. May Be my assumption is wrong. So for now no solid reason, but we have solution. So for now just solve this issue and move faster to meet your deadlines.

Getting “Default New User License” of customer portal in apex code.

Sometime we need to get Default New User License of Customer Portal in the apex code, After doing some google search, I found that there is no direct method or way to do it in the apex.

To get the Default New User License of customer portal in apex code, we need either customer portal name or site name. Below are the steps for Getting “Default New User License” of customer portal in apex code. Here you go :-

Getting Default New User License of Customer Portal in Code

STEP 1 : You need MetadataService.cls Apex class in your salesforce org.(I would suggest keep only required methods of your need only, as this class has huge lines of code).
STEP 2 : Now you need to set Remote Site Setting. Setting up remote site setting is shown in below figures.

Setup Remote Site Setting
Setup Remote Site Setting
Setup Remote Site Setting for VF Page.
Setup Remote Site Setting for VF page.

STEP 3 : After setting up MetaDataService apex class and remote site setting we are ready to read “Default New User License” of customer portal in apex code. Given below is the code snippet for this.

Disable Inline Editing on Apex:EnhancedList through jquery script

Sometimes we don’t want to keep inline editing on the apex:enhancedList, and unfortunately there is no standard way to disable inline editing. But there is always a solution for , not a standard way but we can say workaround to fulfill the requirement.

Here is the jQuery code snippet which can be put in a javascript function and then we can call this function on the “oncomplete” attribute of apex:enhancedList. Its obvious that you must include jQuery files for the execution of the below code snippet.

C – Authentication Program with username and password

C-Authentication program will helps to add an authentic step before getting into your program. This can be used as a security check in any C program.

Customization In Code

In the given code for Authentication in C language, you can specify following properties/values as per your choice.

  • Username
  • Password
  • Number of maximum attempts
C-Authentication program
C-Authentication program output
Source Code


C – Guess the secret sentence character by character

Here you will get complete source code guessing a character in a secret sentence or word in C Programming language. you can set your secret message or sentence in the code and then you can tell your friend to start guessing that secret message after executing the code.

One of my Facebook Page’s fan Faster Msr posted this on my page, so I coded to implement this using C Programming language.

Guess the word
Guess the word (“C Lover” at back-end).
Guess the word
Guess the word (Guessed it!).
Source Code of Program.


C program for all number conversion.

I have created a C program for all number conversion, its a small application using C language. I have used printf’s various format specifiers to minimize the code and utilizing the available features of printf function.

These are some of format specifiers used in the code.
  • %d => for signed decimal integer.
  • %o => unsigned octal integer.
  • %X => unsigned hexadecimal integer.
The number conversions supported by this code are listed below.
  • Binary to Octal
  • Binary to Decimal
  • Binary to Hexadecimal
  • Octal to Binary
  • Octal to Decimal
  • Octal to Hexadecimal
  • Decimal to Binary
  • Decimal to Octal
  • Decimal to Hexadecimal
  • Hexadecimal to Binary
  • Hexadecimal to Octal
  • Hexadecimal to Decimal

C program for all number conversion
All Number Conversions using C

Pyramid using C with a new logic.

There are many ways of solving a programming problem , and every one has his own logic to solve a problem. Here I also implemented a new logic using C language’s printf() function.
printf() function is more than just writing output to the screen i.e. it returns the number of characters it writes on the output screen.

One functionality of printf() is as follows.

printf(“Hello”+1); = ello
printf(“ABCDE”+2); = CDE
It skips the first n characters if we are using printf(“message”+n);

Another functionality of printf method is :

If we write =>  int num = printf(“Hello”); . Then num will have value 5 (Hello has 5 letters).

Similarly if we write,

int num = printf(“2017”);. Then num will have value 4 (2017 has 4 characters).

Pyramid Using C
Pyramid Using C