JSON output in Visualforce

Author posted by Jitendra on Posted on under category Categories Apex, Salesforce, Visualforce and tagged as Tags , , with 9 Comments on JSON output in Visualforce

The Example of generating the JSON Output in Visualforce page using JSON.serialize method provided by Salesforce

In this article, i will demonstrate using the JSON.serialize() method provided by the Salesforce to convert the class into equivalent JSON String.

Before going into depth would like to explain the basic concept of JSON syntax for the newbie.

There are following thumb rules i have identified from my experience, please comment in this article if i miss something here:

  • The JSON stands for “Java Script Object Notation“.
  • JSON is used widely as an option to xml, because the xml is very verbose whereas the JSON is having very simple representation.
  • It Simply have a key and value pair combination.
  • DataTypes supported by the JSON are “Number, String, Boolean, Array, Object and null”.
  • Key and value pair are separated by colon “:”
  • Object is enclosed between curly brackets “{” and “}”.
  • Array is enclosed using square bracket “[“, “]” separated by the comma.

Example of JSON syntax:

{
     "firstName": "Jitendra",
     "lastName" : "Zaa",
     "age"      : 26,
     "address"  :
     {
         "streetAddress": "21 2nd Street",
         "city"         : "Nagpur",
         "state"        : "MH",
         "postalCode"   : "400008"
     },
     "phoneNumber":
     [
         {
           "type"  : "Mobile",
           "number": "212 555-1234"
         },
         {
           "type"  : "Home",
           "number": "646 555-4567"
         }
     ]
 }

Download Source code – Visualforce page as JSON
Continue reading “JSON output in Visualforce”

Handling Colon in Element ID in JQuery – Visualforce problem

Resolving the JQuery error when the Element ID contains colon with Live Demo

Today i came across very known problem of jQuery and thought of sharing same with everyone. In Salesforce the element id is in the format of “j_id0:j_id3:j_id4:c_txt“. In previous post we have already discussed about getting the elementId in Visualforce.
When i tried to find the element in JQuery like $(‘#j_id0:j_id3:j_id4:c_txt’), i was getting the error on JavaScript console of the browser. After few searches, i got to know that this is known problem and faced by many of the developers.

Live Demo

Continue reading “Handling Colon in Element ID in JQuery – Visualforce problem”

Salesforce Interview Questions – Part 5

Basic concepts and Interview Questions of salesforce, Visualforce, Apex and SOQL

40. What is Master Detail relationship and look up relationship in Salesforce?
Ans:
Master Detail relationship is the Parent child relationship. In which Master represents Parent and detail represents Child. If Parent is deleted then Child also gets deleted. Rollup summary fields can only be created on Master records which will calculate the SUM, AVG, MIN of the Child records.
Look up relationship is something like “has-a” (Containership) relationship. Where one record has reference to other records. When one record is deleted then there is no impact on other records.


41. Can we convert the lookup relationship to Master Detail relationship?
Ans:
We can convert the lookup relationship to master detail relationship if and only if all the existing record has valid lookup field.


42. In How many way we can invoke the Apex class?
Ans:

  1. Visualforce page
  2. Trigger
  3. Web Services
  4. Email Services

Continue reading “Salesforce Interview Questions – Part 5”

Get DOM ElementID of the Visualforce components

Author posted by Jitendra on Posted on under category Categories Salesforce, Visualforce and tagged as Tags with 3 Comments on Get DOM ElementID of the Visualforce components

How to get the DOM ElementID of the Visualforce components in Salesforce

This article will focus on getting generated dom element Id in Visualforce.
Let’s consider below code snap:

<apex:page>
<apex:form id="frm">
Enter Value 1 :
<apex:inputText id="txt1" />
</apex:form>
</apex:page>

If you want to get the id of “apex:inputText” in javascript like belowCode

Var fld =  document.getElementById("˜txt1');

It will NOT work.
Because its actual id will be something like “j_id0:frm:txt1“.

Continue reading “Get DOM ElementID of the Visualforce components”

Getting record from other Salesforce organization OR communication between multiple salesforce organization

Calling Rest Web service using Apex – Getting record from other Salesforce organization or Account or communication between multiple salesforce organization

In this article, I will explain the code which can be used for connecting and getting the records from different or multiple salesforce organization using Apex and REST Service.

Note : Here is new article to connect two salesforce instances in just 5 lines of code using Named Credentials.

To start first we will need to authorize below two URL which can be accessed from salesforce environment.
This can be done from “Setup | Administration Setup | Security Controls | Remote Site Settings”

  1. https://www.salesforce.com
  2. https://ap1-api.salesforce.com
Salesforce Remote Site Setting
Salesforce Remote Site Setting

Continue reading “Getting record from other Salesforce organization OR communication between multiple salesforce organization”

Passing multiple Parameters in ActionFunction in Visualforce

Example and Source code of multiple Parameters Parameter in ActionFunction in Visualforce – Salesforce

Calling Apex Method from the Visualforce page is the one of the most required functionality in application development in Salesforce. <apex:actionFunction> is one of the method used to achieve this functionality.

Most often we need to supply the arguments in <apex:actionFunction> and in this article I will demonstrate the way in which we can pass one or more than one parameter.
The output of the example will be like below screen.

Passing Parameter in ActionFunction in Visualforce
Passing Parameter in ActionFunction in Visualforce

Create Apex class with following code: Continue reading “Passing multiple Parameters in ActionFunction in Visualforce”