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.

SOQL query in javascript

We can use SOQL in java-script on Visual Force pages or we can get it executed on click of a button or link present on detail page of a record. Below is the simple example of SOQL query in javascript on click of a button:
Javascript code:

{!REQUIRESCRIPT("/soap/ajax/24.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/24.0/apex.js")}
try{
var query = "SELECT Id,Name from Contact LIMIT 1";
var result = sforce.connection.query(query);
var arrayResult = result.getArray('records'); 
 
if(arrayResult.length == 0){
alert('There is no Contact');
}
else{
var contactName = arrayResult[0].Name;
alert(contactName);
}
}
catch(e){
alert('An error has occured');
}

Modal dialogue box using apex and visualforce page

To create a modal dialogue box in visualforce page follow below steps.

  • Login to your Salesforce.com developer account.
  • Click “Setup” in the upper right corner.
  • Under the App Setup section (left menu), expand Develop.
  • Click on Apex Classes.
  • Click the “New” button to create a new Apex Class.
  • Add the following source and click the “Save” button.
    public class TestPopup{
        public boolean DisplayPopup {get; set;}    
        
        public void ClosePopup() {       
            DisplayPopup = false;   
        }
     
        public void ShowPopup() {       
            DisplayPopup = true;   
        }
      }
    
  • Click on Pages (below Apex Classes on the left menu).
  • Create a new Visualforce page by clicking the “New” button.
  • For the purpose of this tutorial I used “TestPopupPage” for my Label & Name.
  • Enter the Visualforce Markup code below and click “Save”.
    <apex:page controller="TestPopup">
        <apex:form>
            <apex:commandbutton action="{!ShowPopup}" rerender="TestPopup" value="Show Popup">
            <apex:pageblock>
                This is a sample Test Popup Page.
            </apex:pageblock>
            <apex:outputpanel id="TestPopup">
            <apex:outputpanel layout="block" rendered="{!DisplayPopUp}" styleclass="popupBackground">
                <apex:outputpanel layout="block" rendered="{!DisplayPopUp}" styleclass="customPopup">
                    Hi, Biswajeet 
                    <apex:commandbutton action="{!ClosePopup}" rerender="TestPopup" value="Close Popup">
                </apex:commandbutton></apex:outputpanel>
            </apex:outputpanel>
     
        </apex:outputpanel></apex:commandbutton></apex:form>
     
    
    <style type="text/css">
            .customPopup{
                background-color: white;
                border-width: 2px;
                border-style: solid;
                z-index: 9999;
                left: 50%;
                padding:10px;
                position: absolute;        
                width: 300px;
                margin-left: -250px;
                top:100px;
            }
            .popupBackground{
                background-color:black;
                opacity: 0.20;
                filter: alpha(opacity = 20);
                position: absolute;
                width: 100%;
                height: 100%;
                top: 0;
                left: 0;
                z-index: 9998;
            }
        </style>
    
    </apex:page>
    
  • Now, to view the created visualforce page, you’ll need to go up to the browser address bar and navigate to the apex directory in your Salesforce.com account and type in the page name.
    For me, that is the following: https://na3.salesforce.com/apex/TestPopupPage
    or, you can create a new tab for this visualforce page, and can view it on click of the new created tab.

Here is the output comes up:

Created Visualforce Page:

download

After click on the button, modal popup is displayed:

download (1)

SQL Server Date Formats

Date Format Standard SQL Query Output
MM/DD/YY USA SELECT CONVERT(VARCHAR(8), GETDATE(), 1) 05/23/14
MM/DD/YYYY USA SELECT CONVERT(VARCHAR(10), GETDATE(), 101) 05/23/2014
YY.MM.DD ANSI SELECT CONVERT(VARCHAR(8), GETDATE(), 2) 14.05.23
YYYY.MM.DD ANSI SELECT CONVERT(VARCHAR(10), GETDATE(), 102) 2014.05.23
DD/MM/YY British/French SELECT CONVERT(VARCHAR(8), GETDATE(), 3) 23/05/14
DD/MM/YYYY British/French SELECT CONVERT(VARCHAR(10), GETDATE(), 103) 23/05/2014
DD.MM.YY German SELECT CONVERT(VARCHAR(8), GETDATE(), 4) 23.05.14
DD.MM.YYYY German SELECT CONVERT(VARCHAR(10), GETDATE(), 104) 23.05.2014
DD-MM-YY Italian SELECT CONVERT(VARCHAR(8), GETDATE(), 5) 23-05-14
DD-MM-YYYY Italian SELECT CONVERT(VARCHAR(10), GETDATE(), 105) 23-05-2014
HH:MM:SS   SELECT CONVERT(VARCHAR(8), GETDATE(), 108) 07:28:42
MM-DD-YY USA SELECT CONVERT(VARCHAR(8), GETDATE(), 10) 05-23-14
MM-DD-YYYY USA SELECT CONVERT(VARCHAR(10), GETDATE(), 110) 05-23-2014
YY/MM/DD Japan SELECT CONVERT(VARCHAR(8), GETDATE(), 11) 14/05/23
YYYY/MM/DD Japan SELECT CONVERT(VARCHAR(10), GETDATE(), 111) 2014/05/23
YYMMDD ISO SELECT CONVERT(VARCHAR(6), GETDATE(), 12) 140523
YYYYMMDD ISO SELECT CONVERT(VARCHAR(8), GETDATE(), 112) 20140523
HH:MI:SS:MMM(24H)   SELECT CONVERT(VARCHAR(12), GETDATE(), 114) 07:30:15:913
YYYY-MM-DD HH:MI:SS(24h) ODBC Canonical SELECT CONVERT(VARCHAR(19), GETDATE(), 120) 2014-05-23 07:30:28
YYYY-MM-DD HH:MI:SS.MMM(24h) ODBC Canonical
(with milliseconds)
SELECT CONVERT(VARCHAR(23), GETDATE(), 121) 2014-05-23 07:30:49.337
YYYY-MM-DDTHH:MM:SS:MMM ISO8601 SELECT CONVERT(VARCHAR(23), GETDATE(), 126) 2014-05-23T07:31:03.303
DD/MM/YYYY HH:MI:SS:MMMAM Hijiri SELECT CONVERT(VARCHAR(25), GETDATE(), 131) 24/07/1435 7:31:16:803AM

Add Custom Button to a salesforce standard Page

To create a new custom button go to “Your Name” > Setup > Develop > objects and click the object on which you want to use custom button.
Step 1:
“Your Name” > Setup

1

Step 2:
Develop > Objects

2

Step 3:
Now you can see the list of all custom objects. Select the object where you want to create a new custom button.

3

Step 4:
Now you can see the custom object page. Scroll down to the (Buttons, Links, and Actions) section and click on the New Button or Link.

4

Step 5:
At the next page you need to define some parameters for the custom button. Very important is that you selects Detail Page Button radio button. In this example i have selected Execute Javascript for the behavior, you can adjust it as you want. Now click on Save.

5

Step 6:
Now the “Test Button” is in button list.

6

Step 7:

At the next page click on the Back to Custom Object: Your Object Name to go back to the custom object page.
Now you have to insert your new custom button to the page layout to be able to see it. Scroll down to the Page Layout section and click on Edit link.
At the layout page select Buttons at the left top corner and the click and drag your custom button to the layout.

7

Now save the layout and then go to the custom object item page to see your new created custom button.

Schedule an apex job

To create and test a schedulable class, let’s take a look at how to schedule the class using the user interface.

  1. Create an apex which implemented the schedulable.
    global class TestScheduleService implements Schedulable
    {
        global void execute(SchedulableContext SC)
        {     
            YourServiceClass.serviceExecute();
        }    
    }
    
  2. Your Name -> Setup
  3. App Setup -> Develop -> Apex Classes
  4. Schedule Apex button at the top -> Click Schedule Apex button
  5. Here you can manually schedule an apex class which implemented the schedulable interface.

download