Category Archives: JavaScript

Calling Visualforce Page From Javascript

Visualforce page that calls another Visualforce page upon confirming from javascript.

Visualforce Page:

<apex:page standardController="Account">
    <apex:form>
        <apex:pageBlock>
            <apex:commandButton value="Open VF Page" onclick="OpenVFPage()"/>
        </apex:pageBlock>
    
    <script>
      function OpenVFPage(){
        var isConfirm = confirm('Do you want to open a new Visualforce Page?');
        if(isConfirm)
           window.open('/apex/YourVisualForcePage');
      }
     </script>
    </apex:form>
</apex:page>

Similarly, if you want to open a visualforce page from a custom button using javascript then use following piece of code.

{!REQUIRESCRIPT("/soap/ajax/22.0/connection.js")} 
var isConfirm = confirm('Do you want to open new Visualforce Page?');
if(isConfirm){
	window.parent.location.href="/apex/YourVisualforcePage";
}

Web Browser Language Identification Codes


Language Code
Afrikaans af
Albanian sq
Arabic (Standard) ar
Arabic (Algeria) ar-dz
Arabic (Bahrain) ar-bh
Arabic (Egypt) ar-eg
Arabic (Iraq) ar-iq
Arabic (Jordan) ar-jo
Arabic (Kuwait) ar-kw
Arabic (Lebanon) ar-lb
Arabic (Libya) ar-ly
Arabic (Morocco) ar-ma
Arabic (Oman) ar-om
Arabic (Qatar) ar-qa
Arabic (Saudi Arabia) ar-sa
Arabic (Syria) ar-sy
Arabic (Tunisia) ar-tn
Arabic (U.A.E.) ar-ae
Arabic (Yemen) ar-ye
Aragonese ar
Armenian hy
Assamese as
Asturian ast
Azerbaijani az
Basque eu
Bulgarian bg
Belarusian be
Bengali bn
Bosnian bs
Breton br
Bulgarian bg
Burmese my
Catalan ca
Chamorro ch
Chechen ce
Chinese zh
Chinese (Hong Kong) zh-hk
Chinese (PRC) zh-cn
Chinese (Singapore) zh-sg
Chinese (Taiwan) zh-tw
Chuvash cv
Corsican co
Cree cr
Croatian hr
Czech cs
Danish da
Dutch (Standard) nl
Dutch (Belgian) nl-be
English en
English (Australia) en-au
English (Belize) en-bz
English (Canada) en-ca
English (Ireland) en-ie
English (Jamaica) en-jm
English (New Zealand) en-nz
English (Philippines) en-ph
English (South Africa) en-za
English (Trinidad & Tobago) en-tt
English (United Kingdom) en-gb
English (United States) en-us
English (Zimbabwe) en-zw
Esperanto eo
Estonian et
Faeroese fo
Farsi fa
Fijian fj
Finnish fi
French (Standard) fr
French (Belgium) fr-be
French (Canada) fr-ca
French (France) fr-fr
French (Luxembourg) fr-lu
French (Monaco) fr-mc
French (Switzerland) fr-ch
Frisian fy
Friulian fur
Gaelic (Scots) gd
Gaelic (Irish) gd-ie
Galacian gl
Georgian ka
German (Standard) de
German (Austria) de-at
German (Germany) de-de
German (Liechtenstein) de-li
German (Luxembourg) de-lu
German (Switzerland) de-ch
Greek el
Gujurati gu
Haitian ht
Hebrew he
Hindi hi
Hungarian hu
Icelandic is
Indonesian id
Inuktitut iu
Irish ga
Italian (Standard) it
Italian (Switzerland) it-ch
Japanese ja
Kannada kn
Kashmiri ks
Kazakh kk
Khmer km
Kirghiz ky
Klingon tlh
Korean ko
Korean (North Korea) ko-kp
Korean (South Korea) ko-kr
Latin la
Latvian lv
Lithuanian lt
Luxembourgish lb
FYRO Macedonian mk
Malay ms
Malayalam ml
Maltese mt
Maori mi
Marathi mr
Moldavian mo
Navajo nv
Ndonga ng
Nepali ne
Norwegian no
Norwegian (Bokmal) nb
Norwegian (Nynorsk) nn
Occitan oc
Oriya or
Oromo om
Persian fa
Persian/Iran fa-ir
Polish pl
Portuguese pt
Portuguese (Brazil) pt-br
Punjabi pa
Punjabi (India) pa-in
Punjabi (Pakistan) pa-pk
Quechua qu
Rhaeto-Romanic rm
Romanian ro
Romanian (Moldavia) ro-mo
Russian ru
Russian (Moldavia) ru-mo
Sami (Lappish) sz
Sango sg
Sanskrit sa
Sardinian sc
Scots Gaelic gd
Sindhi sd
Singhalese si
Serbian sr
Slovak sk
Slovenian sl
Somani so
Sorbian sb
Spanish es
Spanish (Argentina) es-ar
Spanish (Bolivia) es-bo
Spanish (Chile) es-cl
Spanish (Colombia) es-co
Spanish (Costa Rica) es-cr
Spanish (Dominican Republic) es-do
Spanish (Ecuador) es-ec
Spanish (El Salvador) es-sv
Spanish (Guatemala) es-gt
Spanish (Honduras) es-hn
Spanish (Mexico) es-mx
Spanish (Nicaragua) es-ni
Spanish (Panama) es-pa
Spanish (Paraguay) es-py
Spanish (Peru) es-pe
Spanish (Puerto Rico) es-pr
Spanish (Spain) es-es
Spanish (Uruguay) es-uy
Spanish (Venezuela) es-ve
Sutu sx
Swahili sw
Swedish sv
Swedish (Finland) sv-fi
Swedish (Sweden) sv-sv
Tamil ta
Tatar tt
Teluga te
Thai th
Tigre tig
Tsonga ts
Tswana tn
Turkish tr
Turkmen tk
Ukrainian uk
Upper Sorbian hsb
Urdu ur
Venda ve
Vietnamese vi
Volapuk vo
Walloon wa
Welsh cy
Xhosa xh
Yiddish ji
Zulu zu

JSON

Biswajeet   May 3, 2014   No Comments on JSON

JSON (JavaScript Object Notation) is a lightweight and text-based data-interchange format. Supports with UTF-8 and date-time information in ISO8601 format. It uses string value pairs for storing data.

Basically it is used to transmit data between a browser and a server. When exchanging data between a browser and a server, the data can only be text. JSON is text, and we can convert any JavaScript object into JSON, and send JSON to the server.

Example:

{
   "firstName":"Biswajeet",
   "lastName":"Samal",
   "isAlive":true,
   "age":28,
   "address":{
      "streetAddress":"25 2nd Street",
      "city":"New York",
      "state":"NY",
      "postalCode":"10021-3100"
   },
   "phoneNumbers":[
      {
         "type":"home",
         "number":"212 888-1234"
      },
      {
         "type":"office",
         "number":"646 989-4567"
      },
      {
         "type":"mobile",
         "number":"123 456-7890"
      }
   ],
   "children":[

   ],
   "spouse":null
}

JSON supports following data types:

  • string
  • {"name":"Biswajeet Samal"}
  • number
  • {"age":28}
  • object
  • {
    "employee":{ "name":"Biswajeet Samal", "age":28, "city":"London" }
    }
  • array
  • {
    "employees":[ "Biswajeet", "Abhijeet", "Satyajeet" ]
    }
  • boolean
  • {"isAlive":true}
  • null
  • {"spouse":null}

Passing Variables from Apex to JavaScript

Sometimes we need to pass variables from apex to javascript. Here is an example to pass variables from apex to javascript. In below example I’m invoking one apex method using action function. In the apex method I’m defining the apex variable value. On complete of action function I’m invoking one javascript method and using the apex variable in the javascript method.

Visualforce Page:

<apex:page controller="SampleController">  
    <apex:form>
        <apex:outputPanel id="jspanel"> 
            <script>  
            function onCompleteMethod() {
                alert('{!message}')
            }
            </script>
        </apex:outputPanel>
        <apex:actionFunction name="afHelloWorld" action="{!HelloWorld}" rerender="jspanel"/>
        <apex:commandButton onclick="afHelloWorld();" oncomplete="onCompleteMethod()" value="Click me"/>
    </apex:form>
</apex:page>

Apex Class:

public class SampleController {
    
    public String message {get;set;}
    
    public pageReference HelloWorld() {
        message = 'Hello World!!';
        return null;
    }   
}