select query in java script salesforce

Sometimes we may need to query records in java script in salesforce. For this we can use "sforce.connection.query". Let us demo how we can query records from any object and iterate through the returned records.

In the following example we will query 10 account records and also iterate through the retured records. Create a custom button on any object and override it with a java script as below.

{!REQUIRESCRIPT("/soap/ajax/20.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/20.0/apex.js")} 

Result = sforce.connection.query("Select Name, Id from account limit 10");

records = Result.getArray("records");

for (var i=0; i< records.length; i++) {

      var accRecord = records[i];
      log(Account Name + " -- " + accRecord.Name);
   log(Account Id + " -- " + accRecord.Id);



The returned records can be debugged using log.

what is cloud computing

Cloud computing services are evolving like anything. Companies of all sizes are adapting to the cloud computing technology. Cloud technology could either be private or public. There are 3 models that are fundamentally used in cloud computing
1. Platform as a service 
2. Infrastructure as a service  
3. software as a service 

There is 99% chance that you as an individual have already used
cloud computing. If you have an web based mail account hosted by gmail, yahoo, hotmail etc or if you have a facebook account, picasa account then you have already experienced cloud computing. Instead of storing the mails on your computer you store them some where else, you use a browser to connect to the Internet and access the mails.The software and storage for your account doesn't exist on your computer. It is with the cloud computing
service provider company. You as an user simply access the services in cloud with your computer and an interface software which could be a simple browser. But, in the back end there are various computers, servers and data storing systems that create the whole cloud computing system.


Moving to cloud means storing your data files on a remotely located servers, using web based application online not installed on your personal computer. The only thing you will need to access the services of cloud computing is the software Interface that connects you with  cloud computing services this could be a simple browser, rest of the things are taken care of by service providers network. 
With advancement in the cloud technology the applications of cloud computing are turning to be practically limitless. Cloud computing can execute all the programs you could run on your personal normal computer. Maintenance of cloud computing applications is easier, because they do not need to be installed on user's computer and can be accessed from any location.

Any cloud computing company generally has quite a large number of clients, thus they need to have a large amount of digital space to store all the client data. They have to also make sure they create duplicate copies of the data as a back up in case of any break down. Cloud computing service providers offer their services according to below 3 fundamental models:

1. Infrastructure As A Service (IaaS)
This is a raw model which includes offering storage and computing resources which can be used by software developers for building business solutions. IT organisations can deliver solutions for their clients using IAAS model. Cloud users can install their operating system and their applications on the cloud infrastructure.
Example of the companies that provide IAAS are amazon EC2, google compute engine, hp cloud

2. Platform As A Service (PaaS)
This model gives a computing platform on top of which you can build a application as desired. The platform can include operating system, programming language execution service, database and server. Service provider could offer a developer tool which can be used to build services or database services or data storage services on the provided platform. Developers can build an application on this platform without bothering about the underlying hardware and software layers.
Example of PAAS service providers are force.com, heroku, azure cloud services, google app engine.

3. Software As A Service (SaaS)
In this type of model the service provider gives a specific built
application and supporting database. We can say that the application or the software is hosted by provider and you dont have to install anything from your side. You have to just connect using internet to use the application service. An example of application service is CRM or ERP. SAAS delivers single application through the browser to number of customers using a multitenant architecture environment. Salesforce.com is a Best known example of SAAS, that provides CRM application built on force.com. Other examples of SAAS are google apps, microsoft office 365.



Advantages of cloud computing
1. As an user you dont store anything on your computer, so you are not bothered about installing anything or perhaps maintain anything personally.
2. Low cost. Maintenance cost, installation cost are reduced.
3. Easy access, you can access the services (applications and data) easily using software    interface like browser. You only need to be connected to the Internet.
4. Access data from anywhere irrespective of your location as long as you have a computer    and an Internet connection
5. Brings the hardware costs down
6. Clients can access their data from anywhere at any time.
7. Reduces the need for advanced hardware on the client side
8. Data storage requires physical space, with cloud computing you are not bothered about    physical space and its security. Cloud computing service provider takes care of this.
9. Data recovery and backup.
10. Streamlines the business processes.
11. Globalisation, employees can access same services irrespective of their location

Disadvantages of Cloud Computing
1. Security could be one concern as the data resides with the service providers.
2. Privacy of data is other concern.

calling controller method from javascript salesforce

In salesforce we use java script either in a visualforce page or we execute javascript on custom button (i.e a custom button is override with a java script). While the java script is being executed we may require to call a controller class method which may have a piece of code required for custom functionality. In case of visualforce page we may use action function which can call the controller method from java script directly. You can see following post on action function for more details  http://cloudforce4u.blogspot.in/2013/06/actionfunction-in-apex.html

For calling a controller method from java script written to override a custom button, we need to use AJAX method callout. In the example below, a custom button on opportunity is overridden with a java script and from the java script calls a method of a controller class.


{!REQUIRESCRIPT("/soap/ajax/20.0/connection.js")}

{!REQUIRESCRIPT("/soap/ajax/20.0/apex.js")}

sforce.apex.execute("updateStatusClass","MethodeWithoutParameters",{});



First two lines of the java script code makes the AJAX toolkit available in the java script of the custom button. As you can see in the code snippet, we have to use method sforce.apex.execute for calling the controller method. We have to just specify the class name in double quotes followed by coma and then method name in double quotes ("className","Methode of that class",{}) We can also call the controller method from Visualforce page using AJAX.  So as to make the AJAX available in visualforce page we have call it as below

<script src="../../soap/ajax/28.0/connection.js" type="text/javascript">
  <!-- AJAX method here -->
</script>

Following is the class that is being called from above java script.
/* This is a class for demo purpose, methods of this class are called from  java script
a method without parameter as well as method with parameters is called form java script*/

Public Class updateStatusClass{
 Public updateStatusClass(){
  /*This is a constructor of the demo class*/
 }
 /*Method without any parameters */
 Public void MethodeWithoutParameters(){
  system.debug('**Method without any parameters**');
 }
}

salesforce interview questions and answers 9

Part 1 (1-15) - Part 2 (16 -30) - Part 3 (31 -45) - Part 4 (46 -55) - Part 5 (56 -66) - Part 6 (67 - 78) - Part 7 (79 - 90) - Part 8 (91 - 100) - Part 9 (101- 111) - Part 10 (112 - 120) - Part 11 (121 - 130) - Part 12 (131 - 137) - Part 13(138 - 145) - Part 14 (146 - 152) - Part 15 ( 153 - 159) - Part 16 ( 160 - 168) Part 19 (188 - 201)

101. Can you do a dml in constructor?
Ans: No. This cannot be done. You cannot do a dml within a constructor
102. What are the data types that can be returned by a formula field?
Ans: 1.Checkbox 2. currency 3.Date 4.Date/Time 5.Number 6.Percent 7.Text
103. Can you create a new profile from scratch ?
Ans: No, you have to clone from a existing profile and modify the settings as required.
104. What are custom labels in saleforce?
Ans custom labels are custom text values that can be accessed from apex codes and visualforce pages.
105. What is the character limit of custom label ?
Ans: Custom labels can be only 1000 characters long, not more than that.
106. How long can a sandbox name be?
Ans: It can only be of upto 10 characters not more than that.
107. Can you use sharing rules to restrict data access?
Ans No, sharing rule can only give wider access to data it cannot restrict data access.
108. Can you edit a formula field values in a record?
And: formula fields are read only and cannot be edited.
109. Can you edit roll up summary field values in a record?
Ans: No, roll up summary fields are read only and cannot be edited.
110. Ho can you create relationship between two objects in salesforce?
Ans relationship can be set up by crating either look up relationship field or master detail relationship fields on objects.
111. Can you create a roll up summary field on parent object?
Ans: Roll up summary fields can only be created if the relationship between objects is master detail type.
Part 1 (1-15) - Part 2 (16 -30) - Part 3 (31 -45) - Part 4 (46 -55) - Part 5 (56 -66) - Part 6 (67 - 78) - Part 7 (79 - 90) - Part 8 (91 - 100) - Part 9 (101- 111) - Part 10 (112 - 120) - Part 11 (121 - 130) - Part 12 (131 - 137) - Part 13(138 - 145) - Part 14 (146 - 152) - Part 15 ( 153 - 159)- Part 16 ( 160 - 168) Part 19 (188 - 201)

salesfore interview questions and answers 8

Part 1 (1-15) - Part 2 (16 -30) - Part 3 (31 -45) - Part 4 (46 -55) - Part 5 (56 -66) - Part 6 (67 - 78) - Part 7 (79 - 90) - Part 8 (91 - 100) - Part 9 (101- 111) - Part 10 (112 - 120) - Part 11 (121 - 130) - Part 12 (131 - 137) - Part 13(138 - 145) - Part 14 (146 - 152) - Part 15 ( 153 - 159) - Part 16 ( 160 - 168) Part 19 (188 - 201)

91. Can you edit a apex trigger/apex class in production environment ?
Ans: No apex trigger /class cannot be edited in production.
92. Can you edit a visualforce apge in production environment ?
Ans: Yes this can be done.
93.How can you deliver a visualforce page in excel form ?
Ans: use contentType="application/vnd.ms-excel#Contacts.xls" in page component of visualforce page
94. What is trigger.new?
Ans: It is a list of records in current context in a trigger.
95. What does it mean when you get the error "too many soql queries 101 salesforce"
Ans: It means you are hitting the limit of 100 soql queries as per governers limit
96. How can you create a input field for date on a visualforce page ?
Ans: To create a input date field on vf page you will have to bind it with a existing date field on any object.
97. How can you convert a text to upper string ?
Ans: stringname.toUppercase();
98. How can you convert a integer into a string ?
Ans: string.valueof(integerName);
99. What are the different types of email templates that can be created in salesforce?
Ans: Test, HTML (using Letterhead), Custom (without using Letterhead) and Visualforce.
100. How can you display different picklist values for picklist fields in different page layouts?
Ans: This can be done using record types.
Part 1 (1-15) - Part 2 (16 -30) - Part 3 (31 -45) - Part 4 (46 -55) - Part 5 (56 -66) - Part 6 (67 - 78) - Part 7 (79 - 90) - Part 8 (91 - 100) - Part 9 (101- 111) - Part 10 (112 - 120) - Part 11 (121 - 130) - Part 12 (131 - 137) - Part 13(138 - 145) - Part 14 (146 - 152) - Part 15 ( 153 - 159)- Part 16 ( 160 - 168) Part 19 (188 - 201)

salesforce interview questions and answers 7

Part 1 (1-15) - Part 2 (16 -30) - Part 3 (31 -45) - Part 4 (46 -55) - Part 5 (56 -66) - Part 6 (67 - 78) - Part 7 (79 - 90) - Part 8 (91 - 100) - Part 9 (101- 111) - Part 10 (112 - 120) - Part 11 (121 - 130) - Part 12 (131 - 137) - Part 13(138 - 145) - Part 14 (146 - 152) - Part 15 ( 153 - 159)- - Part 16 (160 - 168) Part 19 (188 - 201)
79. What are the different types of sandboxes in salesforce ?
Ans: Developer, Developer Pro, Partial Data and Full are the 4 types of sandboxes in salesforce.
80. With what frequency can you refresh a full copy sandbox?
Ans: full copy sandbox can be refreshed every 29 days from production.
81. How can you make fields required on a visualforce page?
Ans: mark required = true as done in the example below:
     <apex:inputfield value="{!account.Description}" required="true"/>
82. What is minimum coverage for every trigger for deployment?
Ans: every trigger should have a minimum coverage of 1%. Total coverage should be 75%
83. What is minimum coverage for every class for deployment?
Ans: There is no such requirement. A class can have 0% but the total coverage should be >75%
84. How can you implement custom functionality for a standardcontroller visualforce page?
Ans: This can be done by associating a controller class with that standard controller using "Extenssions"
85. How can you get the current record id in a visualforce page ?
Ans use ApexPages.CurrentPage().getparameters().get('id') to get the current record id in visaulforce page.
86. Can a user change his own profile in salesforce ?
Ans: No, a user cannot change change his own profile !!
87. Can a user change his own role?
Ans: Yes this can be done !!
88. Reset security token option is unavailabel in set up. What could be the reason?
Ans: If in the profile setting "login ip ranges" have been set up then the option of "reset security token" is uanvailbale.
89. How can you skip record type selection page(and take up default record type) while creating new record of a aprticular object ?
Ans: just tickmark against the object by navigating to following :
     set up --> my personal information -- > Record type selection --> check against the required object
90. What are the different data types that a standard field record name can have?
Ans: Record name field can have either of the two data types : Auto Number or Text data type
Part 1 (1-15) - Part 2 (16 -30) - Part 3 (31 -45) - Part 4 (46 -55) - Part 5 (56 -66) - Part 6 (67 - 78) - Part 7 (79 - 90) - Part 8 (91 - 100) - Part 9 (101- 111) - Part 10 (112 - 120) - Part 11 (121 - 130) - Part 12 (131 - 137) - Part 13(138 - 145) - Part 14 (146 - 152) - Part 15 ( 153 - 159)- Part 16 (160 - 168) Part 19 (188 - 201)

salesforce interview questions and answers 6

Part 1 (1-15) - Part 2 (16 -30) - Part 3 (31 -45) - Part 4 (46 -55) - Part 5 (56 -66) - Part 6 (67 - 78) - Part 7 (79 - 90) - Part 8 (91 - 100) - Part 9 (101- 111) - Part 10 (112 - 120) - Part 11 (121 - 130) - Part 12 (131 - 137) - Part 13(138 - 145) - Part 14 (146 - 152) - Part 15 ( 153 - 159)- Part 16 ( 160 - 168) Part 19 (188 - 201)
67. Can you use dml statement in visualforce compoenent controller ?
Ans: To use dml in visualforce component you have to declare allowdml=true in visualforce component otherwise you will get an exception
      "DML is currently not allowed"
68. Can you write sosl in trigger>?
Ans: Earlier this was not allowed but now sosl are allowed in triggers.
69. Which are the different access modifiers in apex?
Ans: 1. Private 2. Public 3. Protected 4.Global are the four access modifiers allowed in apex
70. Can you change the master of a detail record in salesforce ?
Ans. Yes provided you have ticked marked "Allow reparenting" in field setting otherwise the field is read only and master cannot be changed.
71. How can you lock records in apex?
Ans: use For update in query to lock the record. For example: [select id,name from contact limit 10 For update];
72. IS there any limit on the number of items that can be stored in apex collections?
Ans: There is ni such limit but we need to consider heap size limit 6mb (6 MB as of now)
73. How can you monitor future actions of time based workflow?
Ans: setup --> administration set up --> monitoring --> time based workflow
74. What is visaulforce component ?
Ans: It is a piece of code that can be reused. It can be encapsulated in other visualforce pages.
75. Ho can you display the status of an AJAX update request in a visualforce page ?
Ans: To display AJAX request status we can use <apex:actionstatus> component.
76. How can you access custom label in apex:
Ans: Example --> string custLabelstr = System.Label.LabelNamehere
77.How can you get all the keys of a map variable ?
Ans: USe method keyset() for this
     Example = Set<id> idSet = mapname.keyset();
78. How can you compare values of a picklist field in validation rule?
Ans : for comparing picklist value use ispickval
      ISPICKVAL(picklist_field, text_to_compare)
Part 1 (1-15) - Part 2 (16 -30) - Part 3 (31 -45) - Part 4 (46 -55) - Part 5 (56 -66) - Part 6 (67 - 78) - Part 7 (79 - 90) - Part 8 (91 - 100) - Part 9 (101- 111) - Part 10 (112 - 120) - Part 11 (121 - 130) - Part 12 (131 - 137) - Part 13(138 - 145) - Part 14 (146 - 152) - Part 15 ( 153 - 159)- Part 16 ( 160 - 168) Part 19 (188 - 201)

Salesforce interview question part 2     
salesforce question and answers part 3 
SFDC Question and answers part 4 
salesforce interview question and answer part 5 
salesforce.com interview question and answer pdf part 6 
salesforce interview questions part 7 
interview question and answers salesforce part 8 
salesforce question and answers part 9 
sfdc question and answers part 10 
latest salesforce interview questions with answers part 11 
salesforce interview questions with answers pdf part 12 
question and answers of salesforce interview part 13 
salesforce.com interview questions and answers part 14 
salesforce interview question part 15 

salesforce interview questions and answers 5

Part 1 (1-15) - Part 2 (16 -30) - Part 3 (31 -45) - Part 4 (46 -55) - Part 5 (56 -66) - Part 6 (67 - 78) - Part 7 (79 - 90) - Part 8 (91 - 100) - Part 9 (101- 111) - Part 10 (112 - 120) - Part 11 (121 - 130) - Part 12 (131 - 137) - Part 13(138 - 145) - Part 14 (146 - 152) - Part 15 ( 153 - 159) - Part 16( 160 - 168) Part 19 (188 - 201)
56. What is sosl?
Ans: select query that can return records of multiple objects as list of lists
57. How many records a select query soql can return?
Ans: as of now the limit is 50000
58. What is the full form of AJAX?
Ans: it stands for assynchronous java and XML
59. Why do we need to write test classes?
Ans: Salesforce does not allow deployment in production if the test coverage is less than 75%
60.How can you show a custom error message in trigger?
Ans: This can be done using addError() method in trigger
61. What is the use of future annotation?
Ans: Future method starts execution when Salesforce has resources available.That is for asynchronous execution.
62. How to identify if a class is a test class?
Ans: test class always begins with @isTest
63. How to convert a blob variable into a string?
Ans Use toString to convert blob into string
64. what are the different methods of batch apex class?
Ans: start method, execute method and finish method
65.What is' with sharing' in apex class code?
Ans: When you use 'with sharing', user's permissions and field-level security are respected. In case of 'without sharing' code runs in system mode.
66. How many records can a sosl return ?
Ans: It can return 2000 records as of now as per governers limit
Part 1 (1-15) - Part 2 (16 -30) - Part 3 (31 -45) - Part 4 (46 -55) - Part 5 (56 -66) - Part 6 (67 - 78) - Part 7 (79 - 90) - Part 8 (91 - 100) - Part 9 (101- 111) - Part 10 (112 - 120) - Part 11 (121 - 130) - Part 12 (131 - 137) - Part 13(138 - 145) - Part 14 (146 - 152) - Part 15 ( 153 - 159) - Part 16( 160 - 168) Part 19 (188 - 201)

salesforce interview questions and answers 4

Part 1 (1-15) - Part 2 (16 -30) - Part 3 (31 -45) - Part 4 (46 -55) - Part 5 (56 -66) - Part 6 (67 - 78) - Part 7 (79 - 90) - Part 8 (91 - 100) - Part 9 (101- 111) - Part 10 (112 - 120) - Part 11 (121 - 130) - Part 12 (131 - 137) - Part 13(138 - 145) - Part 14 (146 - 152) - Part 15 ( 153 - 159) - Part 16 ( 160 - 168) Part 19 (188 - 201)
46. How to embed a visaulflow in a visualforce page ?
Ans: Use this syntex to embed flow in vf page : <flow:interview />
47. How to enable inline editing in visauflorce page ?
Ans You can enable inline editing in visualforce page by using <apex:inlineEditSupport> component.
48. What is trigger.new in trigger ?
Ans: trigger.new is a list of records that are in the context of trigger or becuase of these records(modification,Creation, deletion) the trigger has been called
49. How do we bulkify the trigger ?
Ans: Bulkfification requires iterating over all the records in trigger context
     for example : for(account ac: trigger.new){
                       // your logic here           
                   }
50.How can we get the old value in trigger ?
Ans: use trigger.old map for getting previous values of fields.
51. Can we modify records directly in trigger.new ?
Ans: trigger.new is a read only list, but field values can be changed in case of before trigger
52. What does the error "list has no rows for assignment" mean?
Ans: it means the list you are trying to access has no values in it.
53. Why should we not write select query within for loop?
Ans: Writing select query within for loop may hit the governer limit of 100 select queries.
54. What should we do to avoid view state error in visualforce page?
Ans: Clear unused collections, define variable as transient.
55. What is a sandbox org?
Ans: It is the exact copy of your production org.
Part 1 (1-15) - Part 2 (16 -30) - Part 3 (31 -45) - Part 4 (46 -55) - Part 5 (56 -66) - Part 6 (67 - 78) - Part 7 (79 - 90) - Part 8 (91 - 100) - Part 9 (101- 111) - Part 10 (112 - 120) - Part 11 (121 - 130) - Part 12 (131 - 137) - Part 13(138 - 145) - Part 14 (146 - 152) - Part 15 ( 153 - 159) - Part 16 ( 160 - 168) Part 19 (188 - 201)