Salesforce Interview Questions

What is the difference between a Profile and Role?

Profile deals with CRED (Create, Read, Edit and Delete) permissions over Apps, Tabs, sObjects, Fields, Record Types, etc...

Role: Record Level Access (OWD, Role hierarchy, Sharing rules, Manual Sharing)

Profile: Object Level Access and Field Level Access

Role determines what is visible to the user

Profile determines what actions they are allowed to perform


Permission Set

To improve the permissions for the users over profiles we should go for Permission Sets.

It cannot be used to restrict permissions.

Example: To give additional permissions to few users who belong to different profiles over Apps, Tabs, sObjects, and fields.


What are OWD and sharing rules? [OWD -> Role Hierarchy -> Sharing Rule -> Manual Sharing]

organization-wide sharing settings can be set to Private, Public Read Only, or Public Read/Write. In environments where the organization-wide sharing setting for an object is Private or Public Read Only, an admin can grant users additional access to records by setting up a role hierarchy or defining sharing rules. However, sharing rules can only be used to grant additional access—they cannot be used to restrict access to records beyond what was originally specified with the organization-wide sharing defaults.

By default, Salesforce uses hierarchies, like the role or territory hierarchy, to automatically grant access of records to users above the record owner in the hierarchy.

Setting an object to Private makes those records visible only to record owners and those above them in the role hierarchy. Use the Grant Access Using Hierarchies checkbox to disable access to records to users above the record owner in the hierarchy for custom objects in Professional, Enterprise, Unlimited, Performance, and Developer Edition. If you deselect this checkbox for a custom object, only the record owner and users granted access by the organization-wide defaults receive access to the records.


Sharing Rules in Salesforce make automatic exceptions to your organization-wide sharing settings for a defined set of users.

  • Using Sharing Rules in Salesforce we can extend sharing access to the user in public groups, roles or territories.

  • Sharing rules can never be stricter than Organization wide default settings.

  • We can create Sharing rules based on record owner and field values in the record


In Salesforce, there are three types of sharing rule components they are

  1. Share which records?

  2. With which users?

  3. What kind of access?


What is Queue?

Say you have a team of Sales Users who will work on Leads.

You might get a lot of leads from integration, and not have time to manually assign each one to a specific Sales User.

In this very common case, you'd simply assign the leads to a Queue, then add your Sales Reps as Queue Members so they can pick and choose the leads they want from this Queue!

This component supports cases, leads, service contracts (if Entitlements are enabled), and custom objects.

Queues are stored into Group Objects in Salesforce and Users that are present are being stored into GroupMember Object.


What type of relationship is there between contact and account?

Contacts and Accounts have a lookup relationship but this relationship has a property called CascadeDelete set to true. This is why the contact is deleted when the parent object is deleted.

Account and contact have a lookup relationship. It is lookup because you can create a contact without an account. However it behaves weird –like master detail in business logics – when you create a contact with account and you delete that account then contact will be also deleted.


What is the difference between workflow and process builder?

Process builder is a powerful tool you can use to automate business processes. It has a simple interface that allows you to point and click to select objects and fields while setting up immediate and time-based actions. Process builder allows you to do more than a simple workflow would. It is a tool that allows you to automate business processes using a graphical representation of your process.


You can use the Process Builder to perform more actions than with workflow:

  • Create a record

  • Update any related record

  • Use a quick action to create a record, update a record, or log a call

  • Launch a flow

  • Send an email

  • Post to Chatter

  • Submit for approval

  • Call Apex methods

  • But the process builder doesn’t support outbound messages.

Workflow does only 4 actions

  • Create Task

  • Update Field

  • Email Alert

  • Outbound Message


Different ways to make field mandatory:

  • Make the field “Required” at the time of field creation by checking the “Required” checkbox.

  • Make the field Required through Page Layout by checking the “Required ” checkbook in Field Properties.

  • Validation Rules can also be used to make the field mandatory. In Error Condition Formula, one can use ISBLANK(“FieldName”);.

  • Triggers can be used to make field mandatory. Ex. If a user tries to insert the record without the field which is required, we can throw the page message specifying to fill up required fields.(Using Trigger.addError()).

  • One can make field mandatory through Visualforce. (If the field is getting referenced) by setting the required attribute in <apex:inputField> to True.


What is a list view and how is it related to queue?

List Views are created by default for a corresponding Object whenever Queues are created for Cases, Leads, or Custom Objects, but they are not created by default for Queues created for other Objects (for example, the Order Object).


What are trigger context variables?

All triggers define implicit variables that allow developers to access run-time context. These variables are contained in the System.Trigger class.

  • isExecuting

  • isInsert

  • isUpdate

  • isDelete

  • isBefore

  • isAfter

  • New - Returns a list of the new versions of the sObject records. This sObject list is only available in insert, update, and undelete triggers, and the records can only be modified in before triggers.

  • newMap - A map of IDs to the new versions of the sObject records. This map is only available in before update, after insert, after update, and after undelete triggers.

  • Old - Returns a list of the old versions of the sObject records. This sObject list is only available in update and delete triggers.

  • oldMap - A map of IDs to the old versions of the sObject records. This map is only available in update and delete triggers.


What are the best practices for apex triggers & classes?


  • One Trigger Per Object

  • Logic-less Triggers

  • Context-Specific Handler Methods

  • Bulkify your Code

  • Avoid SOQL Queries or DML statements inside FOR Loops

  • Using Collections, Streamlining Queries, and Efficient For Loops

  • Querying Large Data Sets

  • Use @future Appropriately

  • Avoid Hardcoding IDs


Triggers and Order of Execution


On the server, Salesforce:

  • Loads the original record from the database or initializes the record for an upsert statement.

  • Loads the new record field values from the request and overwrites the old values.

  • Executes all before triggers.

  • Runs most system validation steps again,

  • Executes duplicate rules. 

  • Saves the record to the database, but doesn't commit yet.

  • Executes all after triggers.

  • Executes assignment rules.

  • Executes auto-response rules.

  • Executes workflow rules.

  • If there are workflow field updates, updates the record again.

  • If the record was updated with workflow field updates, fires before update triggers and after update triggers one more time

  • Executes processes and flows launched via processes and flow trigger workflow actions.

  • Executes escalation rules.

  • Executes entitlement rules.


Apex transactions:


  • A single unit of operations in Apex is referred to as an Apex transaction

  • Apex transaction boundary can be a trigger, a class method, an anonymous block, a visualforce page or a custom web service method.

  • All operations within the transaction boundary and calls that are made to external code represent a single transaction.

  • The transaction is committed to the database only after all operations finish executing and don’t cause any errors. In case of an error, all changes are rolled back.


Batch Apex

Batch Apex is used to run large jobs (think thousands or millions of records!) that would exceed normal processing limits. Using Batch Apex, you can process records asynchronously in batches (hence the name, “Batch Apex”) to stay within platform limits. If you have a lot of records to process, for example, data cleansing or archiving, Batch Apex is probably your best solution.


global class MyBatchClass implements Database.Batchable<sObject> {

    global (Database.QueryLocator | Iterable<sObject>) start(Database.BatchableContext bc) {

        // collect the batches of records or objects to be passed to execute

    }

    global void execute(Database.BatchableContext bc, List<P> records){

        // process each batch of records

    }    

    global void finish(Database.BatchableContext bc){

        // execute any post-processing operations

    }    

}


Future Apex

Future Apex is used to run processes in a separate thread, at a later time when system resources become available. You use the @future annotation to identify methods that run asynchronously. 


When using synchronous processing, all method calls are made from the same thread that is executing the Apex code, and no additional processing can occur until the process is complete. You can use future methods for any operation you’d like to run asynchronously in its own thread.


global class SomeClass {

  @future

  public static void someFutureMethod(List<Id> recordIds) {

    List<Account> accounts = [Select Id, Name from Account Where Id IN :recordIds];

    // process account records to do awesome stuff

  }

}


Future methods are typically used for:

  • Callouts to external Web services. If you are making callouts from a trigger or after performing a DML operation, you must use a future or queueable method. 

  • Isolating DML operations on different sObject types to prevent the mixed DML error.


Why we cannot call future method from another future method?

Because All future methods and Batch Classes are Asynchronous and we can not call an Asynchronous call from an Asynchronous call.


Queueable Apex

Queueable Apex is essentially a superset of future methods with some extra #awesomesauce. We took the simplicity of future methods and the power of Batch Apex and mixed them together to form Queueable Apex!


public class SomeClass implements Queueable { 

    public void execute(QueueableContext context) {

        // awesome code here

    }


Queueable Apex allows you to submit jobs for asynchronous processing similar to future methods with the following additional benefits:

  • Non-primitive types: 

  • Monitoring:

  • Chaining jobs:


Salesforce.com vs Force.com

Salesforce introduced Salesforce.com cloud-based CRM and Force.com platform for Salesforce developers. It is true that Salesforce.com is built in Force.com platform and not only Salesforce.com instead a number of apps have been developed through Force.com platform. Force.com is a platform, while Salesforce.com is CRM and is used for various sales operation execution needs. So, if you are asking about technicalities of both then on the ground level you can say that Salesforce is based on Force.com.


Difference between "Trigger.New" and "Trigger.old"?

Trigger.new: Returns a list of the new versions of the sObject records. Note that this sObject list is only available in insert and update triggers, and the records can only be modified in before triggers.

Trigger.old: Returns a list of the old versions of the sObject records. Note that this sObject list is only available in update and delete triggers.


Apex Flex Queue

Use the Apex Flex Queue page to view and reorder all batch jobs that have a status of Holding. Or reorder your batch jobs programmatically using Apex code.

You can place up to 100 batch jobs in a holding status for future execution. When system resources become available, the jobs are taken from the top of the Apex flex queue and moved to the batch job queue. Up to five queued or active jobs can be processed simultaneously for each org. When a job is moved out of the flex queue for processing, its status changes from Holding to Queued. Queued jobs are executed when the system is ready to process new jobs.

You can reorder jobs in the Apex flex queue to prioritize jobs. For example, you can move a batch job up to the first position in the holding queue to be processed first when resources become available. Othe-rwise, jobs are processed “first-in, first-out”—in the order in which they’re submitted.

When the system selects the next job from the Apex flex queue for processing, the job is moved from the flex queue to the batch job queue. You can monitor the moved job in the Apex Jobs page by clicking Apex Jobs.

Alternatively, you can use System. FlexQueue Apex methods to reorder batch jobs in the flex queue. To test the flex queue, use the getFlexQueueOrder() and enqueueBatchJobs(numberOfJobs) methods in the System.Test class.


Data Loaded and Import Wizard

One of the key facet of salesforce is import and export data from salesforce. Data loader is a great tool provided by salesforce to achieve this. Mean while Data loader user interface required manual work for this operation however there are many scenario where we need to automate this process like every night at 12:0 pm.To implement theses scenario we need Data Loader CLI (Command Line Interface) to implement this process and windows task scheduler to schedule this process.


Import Wizard :

  • Is designed for less-technical users and smaller, simple imports of up to 50,000 records.

  • Can only import data of : Account , Contact ,Leads , Solution, and Custom Object.

  • For more information, go to Help & Training | Importing Data | Using the Import Wizards.


Data Loader :

  • For complex imports of any size.

  • Can upload more than 50000 records.

  • Can import and export data.

  • Can import data of any object except User.

Sandbox Types

  • Developer Sandbox

A Developer sandbox is intended for development and testing in an isolated environment. A Developer Sandbox includes a copy of your production org’s configuration (metadata).

  • Developer Pro Sandbox

A Developer Pro sandbox is intended for development and testing in an isolated environment and can host larger data sets than a Developer sandbox. A Developer Pro sandbox includes a copy of your production org’s configuration (metadata). Use a Developer Pro sandbox to handle more development and quality assurance tasks and for integration testing or user training.

  • Partial Copy Sandbox

A Partial Copy sandbox is intended to be used as a testing environment. This environment includes a copy of your production org’s configuration (metadata) and a sample of your production org’s data as defined by a sandbox template. Use a Partial Copy sandbox for quality assurance tasks such as user acceptance testing, integration testing, and training.

  • Full Sandbox

A Full sandbox is intended to be used as a testing environment. Only Full sandboxes support performance testing, load testing, and staging. Full sandboxes are a replica of your production org, including all data, such as object records and attachments, and metadata. The length of the refresh interval makes it difficult to use Full sandboxes for development.


With sharing and without sharing

The with sharing keyword allows you to specify that the sharing rules for the current user are considered for the class. You have to explicitly set this keyword for the class because Apex code runs in system context. In system context, Apex code has access to all objects and fields— object permissions, field-level security, sharing rules aren’t applied for the current user. Apex code that is executed with the executeAnonymous call and Chatter in Apex. executeAnonymous always executes using the full permissions of the current user. 

Use the with sharing keywords when declaring a class to enforce the sharing rules that apply to the current user.

Use the without sharing keywords when declaring a class to ensure that the sharing rules for the current user are not enforced.

Say I have 3 classes:

  • public with sharing class A {}

  • public without sharing class B{}

  • public class C{} // Class C is a non-specified-sharing class.

Now, let's consider the following case scenarios:

  1. class B extends A // class B's code now executes in class A's mode, i.e. in "with sharing" mode.

  2. class B calls class A // called code will now be executed in the mode of the class in which it was defined, in this case, in class A's mode, i.e. in "with sharing" mode.

  3. class C calls class A // called method's code in class A will execute in class A's mode, i.e. in "with sharing" mode.

  4. class C extends class A // code in class C now executes in the parent class A's mode, i.e. in "with sharing" mode.

  5. class A calls C // code in class C is executed in class C's mode, i.e. in "without sharing" mode although it's sharing settings are unspecified in the class' declaration.

  6. class A extends C // class A's code now executes in the parent class C's mode, i.e. in "without sharing" mode


System mode

System mode is nothing but running apex code by ignoring user's permissions. For example, logged in user does not have create permission but he/she is able to create a record.

In system mode, Apex code has access to all objects and fields— object permissions, field-level security, sharing rules aren't applied for the current user. This is to ensure that code won’t fail to run because of hidden fields or objects for a user.

In Salesforce, all apex code run in system mode. It ignores user's permissions. Only exception is anonymous blocks like developer console and standard controllers. Even runAs() method doesn't enforce user permissions or field-level permissions, it only enforces record sharing.

Standard Controller, Custom Controller and Extension Controller

A custom controller is an Apex class that implements all of the logic for a page without leveraging a standard controller. Use custom controllers when you want your Visualforce page to run entirely in system mode, which does not enforce the permissions and field-level security of the current user.

A controller extension is an Apex class that extends the functionality of a standard or custom controller. Use controller extensions when:

  • You want to leverage the built-in functionality of a standard controller but override one or more actions, such as edit, view, save, or delete.

  • You want to add new actions.

  • You want to build a Visualforce page that respects user permissions. Although a controller extension class executes in system mode, if a controller extension extends a standard controller, the logic from the standard controller does not execute in system mode. Instead, it executes in user mode, in which permissions, field-level security, and sharing rules of the current user apply.

StandardSetController


<apex:page controller="myController" tabStyle="Account">

    <apex:form>

        <apex:pageBlock title="Congratulations {!$User.FirstName}">

            You belong to Account Name: <apex:inputField value="{!account.name}"/>

            <apex:commandButton action="{!save}" value="save"/>

        </apex:pageBlock>

    </apex:form>

</apex:page>

<apex:page standardController="Account" extensions="myControllerExtension">

    {!greeting} <p/>

    <apex:form>

        <apex:inputField value="{!account.name}"/> <p/>

        <apex:commandButton value="Save" action="{!save}"/>

    </apex:form>

</apex:page>

<apex:page standardController="Account" extensions="ExtOne,ExtTwo" showHeader="false">

    <apex:outputText value="{!foo}" />

</apex:page>


Create Custom Data Sets (custom setting)

Use custom settings to create custom sets of data, or to create and associate custom data for an org, profile, or user.

Custom settings are similar to custom objects in that they let you customize org data. Unlike custom objects which have records based on them, custom settings let you utilize custom data sets across your org, or distinguish particular users or profiles based on custom criteria.

Custom settings data is exposed in the application cache, which enables efficient access without the cost of repeated queries to the database. This data can then be used by formula fields, validation rules, flows, Apex, and the SOAP API

  1. List Custom Settings

A type of custom setting that provides a reusable set of static data that can be accessed across your organization. If you use a particular set of data frequently within your application, putting that data in a list custom setting streamlines access to it. Data in list settings does not vary with profile or user, but is available organization-wide. 


  1. Hierarchy Custom Settings

A type of custom setting that uses a built-in hierarchical logic that lets you “personalize” settings for specific profiles or users. The hierarchy logic checks the organization, profile, and user settings for the current user and returns the most specific, or “lowest,” value. In the hierarchy, settings for an organization are overridden by profile settings, which, in turn, are overridden by user settings.


Custom metadata

Custom metadata are like custom setting but records in custom metadata type considered as metadata rather than data. These are typically used to define application configurations that need to be migrated from one environment to another, or packaged and installed. 

Custom metadata types are ideal for any records that represent metadata for your app. In other words any records that represents configuration or controls the behavior of your app can be considered for custom metadata. For eg: You want to integrate your application with a number of endpoint. 

Custom Setting

Custom Metadata

Custom settings do not support relationship fields.

You can create lookups between Custom Metadata objects.

You can perform CUD (Create, Update, Delete) operation on custom setting in apex.

You cannot perform CUD (Create, Update, Delete) operation on custom metadata type in apex.

Custom settings are not visible in test class without “SeeAllData” annotation.

Custom metadata type are visible in test class without “SeeAllData” annotation.


Custom Labels

Custom labels are custom text values that can be accessed from Apex classes, Visualforce pages, or Lightning components. The values can be translated into any language Salesforce supports.

You can create up to 5,000 custom labels for your organization, and they can be up to 1,000 characters in length. Custom labels from managed packages don’t count toward this limit.

Lightning Component Bundle 

Each Lightning Component is made up of a Mark-ups, JavaScript controller, a Helper, a Renderer and more (Component Bundle). 

Event

Salesforce Lightning is a component based framework.The communication between components are handled by events.  There are two types for events:

  • Component Event -A component event is fired from an instance of a component. A component event can be handled by the component that fired the event or by a component in the containment hierarchy that receives the event.

  • Application Event - Application events follow a traditional publish-subscribe model. An application event is fired from an instance of a component. 

Events are different. Components don’t send events to another component. That’s not how events work. Components broadcast events of a particular type. If there’s a component that responds to that type of event, and if that component “hears” your event, then it will act on it.

Difference between Render, reRender and renderAs

1. Rendered : It use to place condition for a component(Field, outputpanel, section etc), that will show or not on page.

2. ReRender : It is use after a ajax call, Is component will again check condition for that component.

3. RederAs : It is use for  Visualforce page show  as PDF file or other

Between __c and __r

"__r" is used for retrieving field values from the object's related another object when those objects have relationship via Lookup field.

Let us say you have a Class__c parent object (one) with a child relationship to Student__c objects (many). Now, you want to get the names of the students, and for each student, the name of the class associated with that student. You can use __r relationship to get to Class__c when querying Student__c.

Get names of students and the class name associated with each student's name

Select Student__c.Name, Class__r.Name from Student__c;

Get class name from Class__c and the names of all students associated with the class using Class_c.Students__r

Select Class__c.Name, (Select Name from Students__r) from Class__c;


Error 'Mixed DML Operation’

DML operations on certain sObjects, sometimes referred to as setup objects, can’t be mixed with DML on other sObjects in the same transaction. This restriction exists because some sObjects affect the user’s access to records in the org. You must insert or update these types of sObjects in a different transaction to prevent operations from happening with incorrect access-level permissions. For example, you can’t update an account and a user role in a single transaction. However, deleting a DML operation has no restrictions.

The Mixed DML error is generated – when a User performs DML actions on Setup and non-Setup Objects in the same transaction -because some sObjects affect the user’s access to records in the org. Therefore, a user must insert or update these types of sObjects in different transactions to prevent operations from happening with incorrect access-level permissions.

$A.enqueueAction(action)

$A.enqueueAction(action) adds the server-side controller action to the queue of actions to be executed. All actions that are enqueued will run at the end of the event loop. Rather than sending a separate request for each individual action, the framework processes the event chain and batches the actions in the queue into one request. The actions are asynchronous and have callbacks.



SOSL and SOQL

A SOQL query is the equivalent of a SELECT SQL statement and searches the org database. SOSL is a programmatic way of performing a text-based search against the search index.

Whether you use SOQL or SOSL depends on whether you know which objects or fields you want to search, plus other considerations.


Use SOQL when you know which objects the data resides in, and you want to:

  • Retrieve data from a single object or from multiple objects that are related to one another.

  • Count the number of records that meet specified criteria.

  • Sort results as part of the query.

  • Retrieve data from number, date, or checkbox fields.


Use SOSL when you don’t know which object or field the data resides in, and you want to:

  • Retrieve data for a specific term that you know exists within a field. Because SOSL can tokenize multiple terms within a field and build a search index from this, SOSL searches are faster and can return more relevant results.

  • Retrieve multiple objects and fields efficiently where the objects might or might not be related to one another.

  • Retrieve data for a particular division in an organization using the divisions feature.

  • Retrieve data that’s in Chinese, Japanese, Korean, or Thai. Morphological tokenization for CJKT terms helps ensure accurate results.


Where You Can Use Visualforce in lightning experience

  • Open a Visualforce Page from the App Launcher

  • Add a Visualforce Page to the Navigation Bar

  • Display a Visualforce Page within a Standard Page Layout

  • Add a Visualforce Page as a Component in the Lightning App Builder

  • Launch a Visualforce Page as a Quick Action

  • Display a Visualforce Page by Overriding Standard Buttons or Links

  • Display a Visualforce Page Using Custom Buttons or Links


Where You Can Use Lightning component

  • Add Apps to the Lightning Experience App Launcher

  • Add Apps to Lightning Experience and Salesforce App Navigation

  • Create Drag-and-Drop Components for Lightning App Builder and Community Builder

  • Add Lightning Components to Lightning Pages

  • Add Lightning Components to Lightning Experience Record Pages

  • Launch a Lightning Component as a Quick Action

  • Override Standard Actions with Lightning Components

  • Create Stand-Alone Apps

  • Run Lightning Components Apps Inside Visualforce Pages

  • Run Lightning Components Apps on Other Platforms with Lightning Out


$User.UITheme & $User.UIThemeDisplayed

Use the $User.UITheme and $User.UIThemeDisplayed global variables to determine the current user experience context. 

The difference between the two variables is that $User.UITheme returns the look and feel the user is supposed to see, while $User.UIThemeDisplayed returns the look and feel the user actually sees. 


current user experience context when used in a JavaScript static resource - UITheme.getUITheme

current user experience context when used in Apex - UserInfo.UIThemeDisplayed();


<apex:page standardController="Account">

    <!-- Base styles -->

    <apex:stylesheet value="{!URLFOR($Resource.AppStyles, 'app-styles.css')}" />

    

    <!-- Lightning Desktop extra styles -->

    <apex:variable var="uiTheme" value="lightningDesktop" 

        rendered="{!$User.UIThemeDisplayed == 'Theme4d'}">

        <apex:stylesheet value="{!URLFOR($Resource.AppStyles, 'lightning-styling.css')}" />

    </apex:variable>

    <!-- Rest of your page -->

    

</apex:page>


 Types of bindings used in Visualforce

  • Data binding: Data bindings refer to the data set in the controller.

  • Action bindings: Action bindings refer to action methods in the controller.

  • Component bindings: Component bindings refer to other Visualforce components



Comments

Popular posts from this blog

Install Alfresco Content Service 6.0 on ubuntu 16 using distribution zip

Lucene and fts-search

Call javascript webscript from contoller