Salesforce Interview Questions Sample 3

1) What is Apex Trigger?
Ans: Triggers are used to automate the business process, triggers can be used to perform some actions like Before and After.
Syntax: Trigger Triggername on Object (Before insert)

There are two types of triggers:
Before triggers are used to update or validate record values before they’re saved to the database.
After triggers are used to access field values that are set by the system (such as a record's Id or LastModifiedDate field),
and to affect changes in other records, such as logging into an audit table or firing asynchronous events with a queue.
The records that fire the after trigger are read-only.

2) Difference between WorkFlow and Triggers?
Ans:WF: Workflow will perform operations after record creation/update
    Workflow is declarative(without any coding)
    Executed on a single object
    We cannot perform DML operation on workflow
   
Triggers : Trigger will perform operations before and after record creation/update
           Trigger require coding
           trigger can work across objects
           We can perform DML Operation in 1 trigger

3) What is difference insert() and database.insert() ?
Ans:
Using insert method we can insert the records but if any error occurs in any record system will throw an error insertion fail
and none of the records are inserted.
If we want to execute partially success of bulk insert operation we will use database .insert.

4) What is Static Resources?
Ans: Using Static Resources we can upload images, zip files, jar files, javascript and CSS files that can be referred in a visual force page.
The maximum size of Static Resources for an organization is 250mB.
Syntax: $resource

5) What is Audit Trail?
Ans: Audit trail is used to track all the recent changes that an administrator done to the organization.
This can store the last 6 months data, with this we can debug and verify what changes were done in the org.

6)What is Difference between SOQL and SOSL?
SOQL:
SOQL(Salesforce Object Query Language)
Using SOQL we can Search only on one object at a time.
We can query on all fields of any datatype
We can use SOQL in Triggers and classes.
We can perform DML operation on query results.

SOSL:
SOSL(Salesforce object Search Language)
Using SOSL we can search on many objects at a time.
We can query only on fields whose data type is text,phone and Email.
We can use in calsses but not in Triggers.
We cannot perform DML operation on search result

7) What is a Test class?
Ans: Test class is written to test your code functionality.
For an Org Code coverage of Test class should be >75%
Use @ISTest annotation when we write a test class

8) Best Practices of Test class
a. Use @IsTest annotation
b. Use start test and Stop Test
c. Use System.assetequals or assetnotequals statements
d. Use System.Runas(user)
e. No hardcoded ids for any object
f. Bulkyfy your code.

9)What are salesforce governor limits?
Ans: Salesforce runs on multi-tenant architecture, and in order have the same performance to the database, salesforce has imposed these governor limits.
Basically to avoid monopoly in an Org, ie to maintain security in org , salesforce introduced governor limits.

10) What are various governor limits ?
Ans: Visit https://developer.salesforce.com/docs/atlas.en-us.salesforce_app_limits_cheatsheet.meta/salesforce_app_limits_cheatsheet/salesforce_app_limits_platform_apexgov.htmfor all governor limits
11) What is Batch Apex?
When we have huge number of records to deal with, we use batch apex.
Batch Apex allows you to handle more number of records and manipulate them by using a specific syntax.
We use batch apex to avoid governor limits
Each time you invoke a batch class, the job is placed on the Apex job queue and is executed.

Important points:
To write a Batch Apex class, your class must implement the Database.Batchable interface and include the following three methods:
start()
execute()
finish()
If your code accesses external objects and is used in batch Apex, use Iterable<sObject> instead of Database.QueryLocator.
The default batch size is 200 record.

For more details visit
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_batch_interface.htm

12) What are the different ways of deployment in Salesforce?
Ans: You can deploy code in Salesforce using:

Change Sets
Eclipse with Force.com IDE
Force.com Migration Tool – ANT/Java based
Salesforce Package

13) What are the External Ids?
Ans: External Ids are Number, Email and Text (Record Id).

14) How to get all records even from recycle bin using SOQL query?
Answer : We will need ALL Rows clause of SOQL.
Example :
SELECT COUNT() FROM Opportunity WHERE AccountId = acc.Id ALL ROWS

15)Can you use DML in VF?
Ans: Yes if we use allowDML=true

16) Can we delete a user?
Ans: No we cannot, we can either deactivate or Freeze a user from an Org

17) What are the different type of Collections you can have in Apex?
Ans:
There are three main types of collections…

Lists – A list is an ordered collection of elements that are distinguished by their indices.
Sets – A set is an unordered collection of elements that do not contain any duplicates.
Maps – A map is a collection of key-value pairs where each unique key maps to a single value.

18) Difference between ISBLANK() and ISNULL()
Ans:
ISBLANK() --> Used for text field
ISNULL() --> Used for numeric field

19) How many types of controllers we have?
Ans: Standard Controllers
Customer controllers
Extension Controller

Standard Controllers: Standard controller in Apex, inherits all the standard object properties and standard button functionality directly.
It contains the same functionality and logic that are used for standard Salesforce pages.

Custom Controllers: Custom controller is an Apex class that implements all of the logic for a page without leveraging a standard controller.

Extension Controller: If you want to extend the funtionality standard controllers.
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.

20) What is the use of “@future” annotation?
Future annotations are used to identify and execute methods asynchronously.
If we have @future then it will be executed only when Salesforce has the available resources.

21) What is an sObject type?
Ans: An sObject is any object that can be stored in the Force.com platform database.

22) Apex best practices
Ans: Do not write your SOQl or DML statements in for loops
b. Avoid hard coding ids
c. Bulkify your code
d. Good to use collections…
e. Use @future annotation

23) Execution order in salesforce?
Ans:
Original record is loaded or new record is initialized
System validations rules are executed
Before triggers are executed
custom validation rules are executed
After triggers are executed
Assignment rules are executed
Auto-response rules are executed
Workflow rules are executed
Escalation rules are executed

24) Define WhatID and WhoID
Ans: WhatID refers to an object Ex: Account
     WhoID points to a person
   
25) Apex class runs in which mode?
Ans: System mode

Scenario Based questions:

Converting relationship considerations:
 You can convert a master-detail relationship to a lookup relationship as long as no roll-up summary fields exist on the master object.You can convert a lookup relationship to a master-detail relationship, but only if the lookup field in all records contains a value.

salesforce-interview-questions-sample-4

3 comments:

  1. Hey, Thank you so much for this blog, I started to learn salesforce training online and it is about to complete glad to read this interview questions along with answers blog it is definitely very helpful for me. Thank you for this informative blog.

    ReplyDelete
    Replies
    1. Thanks Anna for your feedback, glad that you found it helpful! Please also review sfdconestop youtube channel too and subscribe :)
      https://www.youtube.com/c/sfdconestop

      Delete