Salesforce Flow Interview Questions for admins – Part 23

Consider it interview questions or FAQs, However below are some high level information or gotchas related to Salesforce Flow.

220+ Salesforce Interview Questions
220+ Salesforce Interview Questions

121. How to create lookup field in Salesforce flow?
Ans : There is no direct way to create a lookup field in flow but we can use workaround mentioned in this post.

122 : How to handle fault in Salesforce flow?
Ans :
We can send emails or fault screen can be created. If any element is connected to second screen, it automatically becomes fault screen and we can use “$Flow.FaultMessage” on screen to show error message. output text can be added on screen with message something like “Sorry, an error occurred in the page. For help, provide your administrator with the following information: {!$Flow.FaultMessage}”. Read more here.

123 : How to redirect Salesforce flow after completion, if end URL is known in advance?
Ans :

There are two approach :

First by using “retURL” parameter in URL of flow

and second,  if flow is used in Visualforce page then

    <flow:interview name="MyUniqueFlow" finishLocation="{!$Page.MyUniquePage}"/>
    <flow:interview name="MyUniqueFlow" finishLocation="{!URLFOR('/home/home.jsp')}"/>

124 : What are difference between lookup and fast lookup data elements in flow?
Ans :
Lookup record will return only first matching record however to get all matching record, we should use fast lookup. Any data element with prefix “fast” means to work in bulk. As shown in below image we have two flavors of Data element in flow for CRUD operation. Continue reading “Salesforce Flow Interview Questions for admins – Part 23”

Salesforce Developers interview questions – Most commonly used code snippets – part 21

Salesforce interview questions – Most frequently used Apex and visualforce code used by Salesforce developers like “How to query and abort scheduled job using Apex”, “Defining VF page as HTML5”, “Visualforce page as JSON” , “Handling colon in element Id for Jquery” , “Chatter using Apex” and many more.

201. Common Apex page attributes.

<apex:page sidebar="false" standardStylesheets="false" showHeader="false">

202. Declare Visualforce page as HTML5.

<apex:page docType="html-5.0" />

203. Visualforce page output as JSON.

<apex:page controller="ControllerName"  contentType="application/x-JavaScript; charset=utf-8" showHeader="false" standardStylesheets="false" sidebar="false">

Continue reading “Salesforce Developers interview questions – Most commonly used code snippets – part 21”

Salesforce interview question related to Lightning framework – Part 20

Salesforce interview questions for Salesforce developers and admin , mostly related to newly released Salesforce Lightning components and applications

191. Why do we still need Visualforce once Lightning will be GA ?
Ans : Visualforce provides the facility for delivering template-driven web pages and email messages. In addition, developers wishing to simply utilize a basic container and maintain more control over the lifecycle of the request may choose Visualforce pages. Finally, organizations that can’t use Apex code can’t use Lightning Components, but they can use Visualforce.

192. What is difference between Visualforce Components and Lightning Components ?
Ans : Visualforce provides the facility for delivering template-driven web pages and email messages. In addition, developers wishing to simply utilize a basic container and maintain more control over the lifecycle of the request may choose Visualforce pages. Finally, organizations that can’t use Apex code can’t use Lightning Components, but they can use Visualforce.

193. Currently, can you show Lightning components tab in Mobile as well in desktop ?
Ans : Currently you can only use Lightning Components in the Salesforce1 Mobile App or a standalone app. Continue reading “Salesforce interview question related to Lightning framework – Part 20”

Salesforce interview questions – Part 19

Salesforce interview questions for developers and admins around Apex, Visualforce, getting Salesforce object name on basis of Id, Apex API limits

181. Lets consider your custom Object named “Training__c” has field “Trainer__c”. You have set some default value in that field. Will that default value apply to new record created by apex code ?
How to make sure that record created from apex code should respect default value of fields ?
Default value in field from Apex code.
Ans :

After API 20, it should automatically populate However there is known issue for same here, click here if it impacts you.
Workaround :
If Default value of field is not getting populated by Apex then we have to use “Dynamic Apex”.  Create instance of object from sObjectType like shown below:

Training__c tr= (Training__c) Training__c.sObjectType.newSObject(null, true);

//Check if Value in field "Trainer__c" is default value
System.assertEquals('Jitendra', tr.Trainer__c);

182. What is best practice to refer dynamic custom messages in Visualforce with multi-language support ?
Ans :
Using Custom Label or OutputField or InputField tag, Platform itself will take care of internationalization. However in some cases, Message needs to be dynamic at the same time it should also support muti-language. In Custom Label, we cannot save dynamic String.

Let’s assume we want to show message something like “DEVELOPERNAME is not authorized to access this page”.
Here, Developername should be dynamically changed in visualforce which supports multilanguage. For each developername, it is not feasible to create custom labels. So below workaround can be used :

Step 1 : Create a Custom Label with text “{0} is not authorized to access this page“. In every language, dynamic value should represented by {0}.

Step 2 : In Controller of Visualforce write something like this :

String developerName = 'Some DeveloperName';
String message = String.format(Label.DEVELOPERNA, new String[] { developerName });

Continue reading “Salesforce interview questions – Part 19”

Large Data Volumes (LDV) in Salesforce | FAQs | Interview Questions

You would like to go through this useful cheat sheet for “Query and Search” optimization, few of this is discussed in this post as FAQ.

171 : How Standard Fields and Custom Fields related information is saved inside Salesforce Database? Is every Standard and Custom Object is created as a different Database table?
Ans :
Salesforce is using Multi-tenant architecture, means many organizations (Tenants) are using same infrastructure. Salesforce Database saves Metadata Information in hundreds of table. Run time engine then generates organization specific query to get information about their organizations and Data from common table as shown in below diagram. Below Database tables are partitioned by Organization ID and generates virtual table specific to Org.

Salesforce Metadata Related Information in Database
Salesforce Metadata Related Information in Database

172 : As a Developer, how can you optimize SQL query to fetch data from Salesforce Database?
Ans :
As Salesforce doesn’t save data in traditional way. Data of all tenants are in common table, so traditional Query optimization query and technique will not work in this case, so there is no such tool available to optimize final generated SQL. We only have option to create SOQL which is optimized by custom inbuilt Query Optimizer.

In Summer14, Salesforce released Query Plan Tool to analyze how query is performing. With help of this tool, we can get an idea how we can change our query to perform better.

173 : When records are created in Salesforce, How it is queued for Indexing?
Ans :
If newly created records are equal to or less than 9000, then it will be indexed in 1 to 3 minutes. However if records are more than 9000, then servers perform bulk indexing at a lower priority, so processing might take longer. Continue reading “Large Data Volumes (LDV) in Salesforce | FAQs | Interview Questions”

FAQ and Best Practices of Test Classes in Apex

Here I am going to share few answers related to Test Classes, which is being asked many times to me by novice Programmers. Please feel free to post Comments if your question is not answered here. I will try my best to add those Questions in this article. If you want to learn Test Class from very basic, you can check this article also.

  1. Best Practices for Test Classes
  2. Use of SmartFactory to auto generate test data
  3. Test method of Controller Extension for StandardController
  4. Test method of Controller Extension for StandardSetController
  5. Why getSelected() method of StandrdSetController is not working
  6. sample Template of class which generates Dummy Data
  7. checking Error Page Messages in Test Classes
  8. Setting Visualforce Page Parameter

What are some Best Practices while writing Test Classes ?

Well, It differs from person to person, as every programmer has its own style of writing code. However I will list few of mine.

  • Very important and first, “Test Coverage Target Should not be limited to 75%”. It is not about coverage, It is about testing complete functionality. It will be always better if your code fails during test execution, It will be less devastating than failing functionality after product release.
  • If possible Don’t use seeAllData=true, Create your Own Test Data.
  • Always use @testSetup method dedicated to create test records for that class. This is newly added annotation and very powerful. Any record created in this method will be available to all test methods of that class. Using @testSetup method will improve test execution performance by creating test records only once for that class. If you are not using this, means test record is created in each TestMethod which will be very slow. Read this Salesforce documentation for more information.
  • Create Different Class which will create Dummy Data for testing, and use it everywhere (You have to be very careful, as sometimes it may slow down test class execution by creating unnecessary data which does not require by every test methods. So few developer prefer test data creation per Test class)
  • If your Object’s Schema is not changing frequently, you can create CSV file of records and load in static resource. This file will act as Test data for your Test Classes.
  • Use As much as Assertions like System.AssertEquals or System.AssertNotEquals
  • Use Test.startTest() to reset Governor limits in Test methods
  • If you are doing any Asynchronous operation in code, then don’t forget to call Test.stopTest() to make sure that operation is completed.
  • Use System.runAs() method to enforce OWD and Profile related testings. This is very important from Security point of View.
  • Always try to pass null values in every methods. This is the area where most of program fails, unknowingly.
  • Always test Batch Capabilities of your code by passing 20 to 100 records.
  • Use Test.isRunningTest() in your code to identify that context of class is Test or not. You can use this condition with OR (||) to allow test classes to enter inside code bock. It is very handy while testing for webservices, we can generate fake response easily.
  • @TestVisible annotation can be used to access private members and methods inside Test Class. Now we don’t need to compromise with access specifiers for sake of code coverage.
  • End your test class with “_Test”. So that in Apex Class list view, Main class and Test class will come together, resulting easy navigation and time saver.

Continue reading “FAQ and Best Practices of Test Classes in Apex”

Apex Interview Question – Salesforce – Part 16

151. Give Sample Code Snippet of Apex that that will show that how Parent and Child record can be inserted in Single Statement ?
Ans : It can be done with help of External Id.

Date dt =;
Opportunity newOpportunity = new Opportunity(Name = 'shivasoft', StageName = 'Prospecting', CloseDate = dt);

Create the parent reference. Used only for foreign key reference  and doesn't contain any other fields. If we provide any other value it will give following error

System.DmlException: Insert failed. First exception on row 1; first error: INVALID_FIELD, More than 1 field provided in an external foreign key reference in entity: Account: []

Account accountReference = new Account(MyExtID__c = 'SHIVA1234567');
newOpportunity.Account = accountReference;

//  Create the Account object to insert.  Same as above but has Name field.  Used for the insert.
Account parentAccount = new Account(Name = 'Shiva', MyExtID__c = 'SHIVA1234567');

    results = Database.insert(new SObject[] {  parentAccount, newOpportunity });

152 . Which SOQL statement can be used to get all records even from recycle bin or Achieved Activities?
Ans : We will need “ALL Rows” clause of SOQL.
Sample :


153. How can you lock record using SOQL so that it cannot be modified by other user.
Ans : we will need “FOR UPDATE” clause of SOQL.
Sample :

 Account [] accts = [SELECT Id FROM Account LIMIT 2 FOR UPDATE];

Continue reading “Apex Interview Question – Salesforce – Part 16”

Salesforce Interview Question – Part 15

141 : User Wants to set the starting day in Calendar as “Monday” instead of “Sunday”. How to get it done?
Ans : Change the user locale to “English ( United Kingdom ) ” in Personal information or User record.

142 : Why CSS is not working in PDF created by Visualforce ?
Ans : In Many cases, i have observed problems faced by my colleagues and complaining that CSS is not working when they try to render any Visualforce page as “PDF”. Same Question is asked many times in Interviews also. Basically there are two ways:

  1. Use “apex:stylesheet” tag to import external CSS file
  2. Wrap “Style” tag inside “Head” tag in Visualforce

143 : How to get Ip Address of User in Apex?
Ans :

String ipAddress = ApexPages.currentPage().getHeaders().get('X-Salesforce-SIP');

True-Client-IP has the value when the request is coming via the caching integration.
X-Salesforce-SIP has the value if there is no caching integration (sandbox, developer edition orgs) or via the secure url.
Thanks to TechNrd for this tips. Continue reading “Salesforce Interview Question – Part 15”