Salesforce Interview Questions – Part 7

61. How to round the double to two decimal places in Apex?

Decimal d = 100/3;
Double ans = d.setScale(2) ;

62.In Profile settings, what is difference between “Modify All Data” and “Modify All” ?

Modify All Data : Create, edit, and delete all organization data, regardless of sharing settings.
Modify All : Give Read, Add, Delete permission to selected Object, Create permission is not included in Modify All  permission.

Gantt Chart in Salesforce using JQuery and JSON

I have searched a lot for any library available for the Gantt Chart however there are very few available on the web. Even i was not able to find out the chart in “Google API”.

In this article, i will delineate creating the “Gantt Chart” using JQuery and JSON. In previous article we have seen that how to generate JSON using Salesforce. So continuing the last article, i will use the same JSON reponse to create the “Gantt Chart”.

What is Gantt Chart?

A Gantt chart is a type of bar chart, developed by Henry Gantt, that illustrates a project schedule. Gantt charts illustrate the start and finish dates of the terminal elements and summary elements of a project.

In this example i am going to create the Gantt Chart for room reservation system. for this i am going to use the JQuery plugin for creating Gantt Chart found here.

Plugin uses following JSON format :

[{  "name"  : "Task#1"
  , "desc"  : " Task Desc"
  , "values": [
      {  "from"       : "/Date(1296547200000)/"
       , "to"         : "/Date(1296554400000)/"
       , "desc"       : "<b>Task #1<br>"
       , "customClass": "ganttRed" (optional)
       , "label"      : "Task #1" (optional)
      {  "from"       : "/Date(1296637200000)/"
       , "to"         : "/Date(1296649800000)/"
       , "desc": "<b>Task #</b>"
       , "customClass": "ganttOrange" (optional)
       , "label": "Task #1" (optional)

However we know that the variable name “from” and “desc” are not valid in Apex because they are keyword. so as a workaround i am replacing the placeholders after the generation of JSON in previous article.

JSON output in Visualforce

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"
           "type"  : "Mobile",
           "number": "212 555-1234"
           "type"  : "Home",
           "number": "646 555-4567"

Download Source code – Visualforce page as JSON

Creating Trigger on Attachment in Salesforce

Lots of time i have seen the question on salesforce developer forum regarding the trigger on Attachment. As this is not a straightway, still we can have trigger on Attachment.

We cannot create trigger on Attachment from the standard salesforce UI however we will have to use the eclipse.

Before insert Trigger on Attachment using eclipse in Salesforce
Before insert Trigger on Attachment using eclipse in Salesforce

While creating the trigger, we have to keep some important points. We should be very careful while writing the trigger on Attachment, as it will be used by any standard or custom Object and therefore the criteria to run trigger for “particular object only” must be handled carefully.

Dynamic Approval Process in Salesforce using Apex and Trigger

Although this is very common approach and lots of articles are around on this topic, still I want to delineate the topic in other way. This topic covers complete scenarios for the approval process based on the Apex class.

Agenda of this article:

  1. Automatically submit the record for approval on the basis of field value.
  2. Automatically select the next Approver.
  3. Approve / Reject the record on the basis of field.


  • Opportunity Object is used.
  • Approval Process is already set on the Opportunity.
  • Field “Next_Approver” will decide that who is going to approve the record.
  • There are three steps in the approval process.
  • There is no test class written and no check for mandatory fields needed for the trigger, as I have considered positive scenarios only.

Important URLS:

API of Approval Process classes:

  1. Apex process
  2. Apex ProcessRequest
  3. Apex_ProcessResult
  4. Apex_ProcessSubmitRequest
  5. Apex_ProcessWorkitemRequest

Steps of Standard approval process defined:

Approval Process Steps
Approval Process Steps

Salesforce Interview Questions – Part 6

51. Explain Permission sets released in Winter 12.
Ans :
A permission set is a collection of settings and permissions that give users access to various tools and functions. The settings and permissions in permission sets are also found in profiles, but permission sets extend users’ functional access without changing their profiles. For example, to give users access to a custom object, create a permission set, enable the required permissions for the object, and assign the permission set to the users. You never have to change profiles, or create a profile for a single use case. While users can have only one profile, they can have multiple permission sets.

Salesforce Interview Questions – Part 5

40. What is Master Detail relationship and look up relationship in Salesforce?
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?
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?

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

Getting record from other Salesforce organization 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”

Salesforce Remote Site Setting
Salesforce Remote Site Setting

Email Services in Salesforce with simple example

What is an Email service in Salesforce?

Email services are automated processes that use Apex classes to process the contents, headers, and attachments of inbound email.

You can associate each email service with one or more Salesforce-generated email addresses to which users can send messages for processing.
The general template to create the apex class for the email services is:

How Email Services works in Salesforce
How Email Services works in Salesforce