salesforce interview questions
salesforce interview questions
Everything we do on the internet is cloud computing, no need for any heavy hardware requirements and no
need to install any software in the local system.
4. What is Production?
Production is the live environment where the end users will use the application. We should not make coding
changes in production since end-users are using the application from a production environment.
5. What is a sandbox?
The environment that we will use for developing or testing purposes is known as a sandbox.
To create the sandbox, in production we can find one link called sandboxes. By clicking on that link we can
create the sandbox by choosing the type of the sandbox.
Developer Sandbox
If we refresh all the sandbox contents will be replaced with production contents.
Copy both configuration and entire real time data from the production.
Customization
1. What is App,Tab,Object,Field in salesforce?
If we enable 'Track Field History', users can see the 'Set History Tracking' button under 'Custom
Fields and Relationships' section which is available on the object detail page.
By clicking on the 'Set History Tracking' button, we can enable tracking for the fields whichever
we want.
To see the object history, go to the object's record layout and add the Object Name History
related list to the layout.
Whenever, user changes a field value from one value to another value, it will show the history
of the field in the 'Object History' related list.
Note that multi-select picklist and large text field values are tracked as edited; their old and
new field values are not recorded.
To create the Activities, while creating the object, we should check for the 'Allow Activities'
checkbox then the user can add open Activities and Activity History related lists on the Object
layout.
Task: Task is nothing but work assigned to a particular person, it doesn't have a certain time
limit.
Event: It has a certain time limit in that time only all persons should assemble after the time
limit is over, event will get complete.
Once the event or task status changes to 'Complete' then we can see those records under
Activity History Related List.
Tab name will be decided based on the Plural Label of the custom object, to rename go to
corresponding object detail page and rename the plural label.
Click on the tab (Which should be related to any of the custom/standard object) > Expand
Force.com Quick Access Menu > Edit Columns > Move the needed fields from Available Fields to
Selected Fields. > Click on Save > User should be able to see multiple columns.
(OR)
Click on Setup > Create > Objects > Select the corresponding object link > Under Search Layouts
section > Click Edit which should be left to Object Tab > Move the needed fields from Available
Fields to Selected Fields. > Click on Save > User should be able to see multiple columns.
ISNULL () works only for number data type fields, if we don't populate with value for number
fields it will return true.
ISNULL () won't support TEXT data type fields because text fields never become null.
We can use checkbox data type fields also while creating dependent picklist (Note: Checkbox
should be always controlling field)
We can use multiselect data type fields also while creating dependent picklist (Note: multi-
select data type field should be always dependent field)
{Controlling field must be either checkbox or picklist } {standard picklist should be always
controlling field but not depend field } {dependent field should be pick list or multiselect}
View - It is the user interface (Apps, Tabs, Page Layouts, Fields and Record Types)
Controller - Business Logic (Save, Edit, New, Cancel and Delete - upon click on these button
salesforce execute some logic from controller)
Model - It is the Database, which stores Schema (Meta-Data (Data about Data) --> Apps, Tabs,
subject’s, fields, Apex Classes, Visualforce pages, etc...) and Instance (Records)
In Salesforce, whenever a user creates any component (Object, field, tab etc ) or record then
salesforce will generate an unique id with which the user can identify the record or component.
After creating the record, in the URL user can see the id of the record which is of 15 digits
length.
Through the user interface the user always sees a 15 digit id which is Cases-Sensitive.
If the user query the existing records from the database through API (Either from Query Tool or
from a program), it will always return an 18 digit id which is Case-Insensitive.
Last 3 digits of the 18 digit represents checksum of the capitalization of 15 digit id.
Based on the first 3 digits the user can identify the object of the record.
All the records belonging to the same object will contain the same first 3 digits.
Record types allow you to offer different business processes, picklist values, and page layouts to
different users based on their profiles
After creating the record type, on the record type detail page user can see all the picklist data
type fields, user can edit the picklist and decide which values should display for this particular
record type.
11. What is the difference between detail page and edit page?
Whenever a user tries to create a new record or edit an existing record user can input the
values for the fields, this page is nothing but an edit page.
After creating a new record or editing an existing record, the user can see the information of
the record, this page is nothing but a detail page.
Visual force tabs (will be created to display the visual force page)
Validation rules help to improve data quality by preventing users from saving incorrect data.
15. There are two fields in an object , the combination of these two fields should be unique,
how to achieve this without coding?
Using the VLOOKUP function in the validation rule we can achieve this.
Since we are working in a multi-tenant environment Salesforce is enforcing the limits for all the
functionalities.
How many external ids we can enable for an object: 7 (increased from 3 to 7 in Winter 15)
These values might be changed , we can extend these limits by raising the case to salesforce.
we can enable the external id for the data types like Text , number, auto number, email.
On the detail page without clicking on the edit button we can edit a particular field if it is not
read-only.
To enable or disable Inline editing follow the below navigation - Setup--> Customise--> User
Interface--> Enable Inline Editing
In list views we can modify multiple records at a time using Enhanced list views Note: To modify
multiple records, all the records should belong to the same record type in the list view
otherwise we cannot modify.
Whenever we click on a tab or we click on a lookup icon or search for a record we see only one
standard field by default, to enable remaining fields -
To show multiple fields for the records which display under a tab, on object detail page > under
Search layouts edit tab and add required fields.
To show multiple fields for the records which display when we click on lookup of a field, on
object detail page > under Search layouts edit Lookup Dialogs and add required fields.
To show multiple fields for the records which display when we search for the records, on object
detail page > under Search layouts edit Search Results and add required fields.
For lookup fields on record detail page we see a link, whenever we put cursor on that link we
see a popup window which displays few fields. To control the fields visibility, on that look up
field parent object page layout we see a mini page layout in that we can control.
To control the picklist values of the Lead status field on the lead object we should create lead
process.
Without selecting the lead process, we can't create the record type for lead object
To control the picklist values of the stage field on the opportunity object we should create sales
process.
Without selecting the sales process, we can't create the record type for opportunity object
To control the picklist values of the status field on the case object we should create support
process.
Without selecting the support process, we can't create the record type for case object
Without login into the salesforce we can create the lead record using web-to-lead.
On lead object we can generate the HTML code by selecting lead fields and by mentioning
return URL from web-to-lead option. The generated HTML code can be hosted in any of the
website. Upon entering the information in those fields and clicking on submit button that
information will be saved into lead object of the Salesforce.
Queue can be crated for custom object and standard object like Lead, Case and Knowledge
Article.
Public group is set of users and it contains individual users. Public group used for sharing
settings and public groups can be created across all objects.
Assignment rule is an automatically assign Lead or Case to the user or queue based on criteria
which you define. You can create multiple assignment rules based on condition but only one
rule should be active at a time.
On lead and case objects we can create the Auto-Response Rules. Whenever any record is
submitted for lead/case if specified condition in the Auto-Response Rules satisfied based on
that we can decide the email format which should send as auto response.
On case object we can create Escalation rule. Based on the priority we can send escalation
mails.
33. I have a lead assignement rule which will update the owner of the lead onwer1 , and
workflow wihch will update the owner of the lead onwer2. finally who will be the owner ?
Questions on Relationships
1. Is it possible to create the Master – Detail Relationship field for the child object which is
having existing records?
No, we cannot create directly. To create first, we should create Look up relationship then
populate the field value for all the records and then convert the look up relationship to master
detail relationship.
If the parent objects don’t have Roll up Summary fields for the child object then we can delete.
To delete a child object it should not be referred in Apex Classes and Apex Triggers.
Later if we undelete the object, Master detail fields on the junction objects will be converted to
look up Fields.
Note:
If we delete only Master – Detail Relationship field from the child object and undelete it from
the Recycle Bin then it will be converted to look up relationship.
Parent Object we cannot delete because it will be referred in the child object.
Master – Detail Relationship data types will be converted to look up relationship data types.
5. What will happen to child records if we delete a parent record in case of Lookup
Relationship?
If we delete parent object record all the child object records relationship's field value will be get
deleted. (Entire record won’t be get deleted)
Example:
Child Object: Employee (Employee object have Department field which is related to
Department Object)
Note:
Salesforce store deleted records only for 15 day in Recycle bin later it will remove the records
permanently.
If we undelete the IT department record from the Recycle bin then all the related child records
department field value will be restored.
6. What will happen to child records if we delete a parent record in case of Master Detail
Relationship?
If we delete the parent object record all the child object records will be get deleted.
Example:
Child Object: Employee (Employee object have Department field which is related to
Department Object)
Note:
Salesforce store deleted records only for 15 day in Recycle bin later it will remove the records
permanently.
If we undelete the IT department record from the Recycle bin then along with IT department
record all the related child (Employee) records will be restored. (We cannot see the child object
records in the Recycle bin)
A child object which is having master detail relationships with two different parent object is
called junction object.
Example:
Object1: Department
Object2: Project
Note: From the above example we can say Employee Object as Junction Object.
8. For a junction object if we delete one of the parent record what will happen to child
records?
Child records will be get deleted which are related to Department as well as Project.
Note: If we undelete the IT department record from the Recycle bin then along with IT
department record all the related child (Employee) records will be restored those will be
reflected for Project as well. (We cannot see the child object records in the Recycle bin)
Users, Profiles and Permission Sets
1. Is it possible to delete the user in salesforce?
No, once we create a user in salesforce we cannot delete the user record. We can only
deactivate the user record.
2. What is 'Grant Account Login Access'? How to enable 'Grant Account Login Access'
If we enable 'Grant Account Login Access' for a user, then we can see 'Log in' button on the
detail page of that user. By clicking on that 'Log in' button without giving that user's username
and password we can log in.
To enable the 'Grant Account Login Access' follow the below steps -
At top right corner click on name (Which should be left to Setup) > My Settings
Left side, click on Personal Information > Grant Account Login Access
In Access Duration column select '1 Year' for all the records and click on 'Save' button.
Log out and Log in as any other user in the organization then click on Manage Users > Users.
User should be able to see list of records and verify the user to whom we enabled the Grant
Account Login Access
User should be able to see the Login link beside Edit link.
Click on Login then user should be able to login as that user mode
Observe at top right corner, user should be able to see logged in as 'Name of the user' which
should be highlighted in black color.
Click on Logout
User should be come back to original user's mode, observe at top right corner, user should not
be able to see Logged in as 'Name of the user'
4. What is Profile?
Profile is a collect of settings and permissions called profile.
FLS, Custom Object Permission, Page Layouts, Record types, Tab Settings, App Settings,
Administrative permission, General permissions and password policies, Apex class access, vf
page access and also Login hours, Login IP range.
Permission set is also found in profile, but permission sets are extended User's functional access
without changing their profile.
Example- To give additional permissions to few users who belongs to different profiles over
Apps, Tabs, sObjects and fields.
6. How to give permissions to two fields for different users who belongs to different profiles?
Permission sets.
1000 (It will depend upon the number of licenses taken by the client, it will be like up to 4000
like that based on the client)
Roles
Sharing Rules.
Manual Sharing
Modify all🡪 we give permission on specific objects (Read, Edit, Delete permission for particular
objects)
View all data🡪 View All Data will give you permission to all records in the system across all
objects
Modify all data 🡪Create, Read, Edit, Delete entire organization (Standard and custom objects)
and regardless of the sharing setting
9. What is role?
Role controls Record level of settings. Role is not mandatory for user creation.
OWD is the default access level on records for any object in sales force.
Private
Public Read/Write
Public Read/Write/Transfer (Only for Case and Lead)
By default, after creating custom object OWD access level is Public Read/Write.
Private: only owner and above hierarchy users can have Read/Write access and below hierarchy
users don't have any access.
Public Read only: only owner and above hierarchy users can have Read/Write access and below
hierarchy users can have only Read Only.
Public Read/Write: Irrespective of role hierarchy everyone can have Read/Write permissions on
the records.
Grant Access using hierarchy enable only for custom object it is possible we can’t change
standard objects
Role A
Role B
Role C
If the Role A user through Manual Sharing or Sharing Rules, shares the record to Role C user
who is in lower hierarchy, then the Role B user who is above in hierarchy to Role C user can see
the records, if we enable Grant Access Using Hierarchies at sharing settings else Role B user
cannot see the record.
Import Wizard and Data Loader
1. What is Import wizard?
It supports custom objects only few Standard objects like Account, Contact, Lead and Solution.
Data Loader is a stand-alone tool to process bulk records. With Data loader we can process
maximum of 5 million records. Most of the time we use only Data loader. Default batch size of
the Data loader is 200.
We can Insert, Update, Delete, Upset, Export, Export all and Hard Delete.
It required installation.
Upsert (To Upsert we should have one external ID field on the object, based on the external id
field if the value already exists it will update, if doesn't exist then it will insert)
Delete (Delete the records based on the id provided, to delete we need only id, deleted records
can be found in recycle bin)
Hard delete (Delete the records based on the id provided, to delete we need only id, deleted
records can't be found in recycle bin, Note: If we enable bulk API in data loader settings then
only we can perform Hard delete.)
Export (From any object we can export records based on the SOQL query, Note: We can't
export deleted records which are there in the recycle bin)
Export all (From any object we can export records based on the SOQL query, Note: Using Export
all we can export deleted records which are there in the recycle bin also)
.SDL
In data loader settings we should enable 'insert null values' checkbox otherwise we can't insert
null values.
Suppose we have account table in Salesforce and account table outside of the Salesforce
(ex: .csv file, sql database). In Salesforce all the records can be identified with record id and
outside of the Salesforce we can't recognize records with Salesforce id that is the reason to
compare outside table and salesforce table in Salesforce for one of the field we have to enable
external ID (we can enable external id for text, number, auto number and email). If we enable
external id we can compare that particular column with the column which is available in
external table. While comparing if the both column values are same then it will update
otherwise it will insert.
2,000 records.
10. What is the best approach to if I don’t want to fire triggers, validation rules , workflows
while loading data ?
Created
Created and every time it’s edited to meet the criteria (if we select this option you can’t add
time-dependent workflow rule action)
Created and any time it’s edited to subsequently meet the criteria
2. What is the difference between Created and every time edited to meet the criteria and
Created and edited to subsequently meet the criteria?
If we select 'Created and every time it’s edited to meet the criteria' whenever we create a
record or edit a record if the criteria of the workflow rule meets, then it will trigger every time.
If we select 'Created and edited to subsequently meet the criteria' -
While creating the record criteria meets so that workflow will fire and while editing the record
again criteria meets workflow won't fire (meeting the criteria to meeting the criteria)
While creating the record criteria doesn't meet so workflow won't fire and while editing the
record workflow criteria meets then workflow will fire (not meeting the criteria to meeting the
criteria)
Conclusion: Previous state of record should be not meeting criteria and current state of record
should be meeting the criteria then only in current state workflow will fire.
Criteria meet (field - operator - value, if there are multiple criteria’s then in filter criteria we can
give conditions like ( 1 or 2) and 3, field to field comparison is not possible, we can't fetch the
previous state information of the field )
Formula evaluated (we can write formulas with this we can do field to field comparison and we
can fetch previous state value of the record)
The action which will be performed in future based on the any of the date field. To create time
dependent workflow action, we should create one-time trigger. In time trigger we can give
either days or hours with the maximum of 999 value and we can select either before or after.
New field update (we can update a field of the same object or the fields of the parent objects
which are at master side in master-detail relationship, only for master-detail parent objects we
can update the field and for lookup we can't update)
New email alert (we can send emails if the criteria meets)
Text
Visual Force
9. There is a time based workflow which will update one of the fields if the criteria meet. User
submits the record with valid criteria, workflow triggered so that the field update is queued
in the 'time based flow' queue which will fire after one day. If the user modifies the record
which is submitted before the scheduled date, after modification, a record criterion is not
meeting. Whether the field will be updated or not in schedule date?
It won't trigger in the schedule date because if we modify the record to not meeting criteria
that queued field update will be removed from the 'time based flow' queue.
10. For the same scenario explained in the above question what happens when we deactivate
or modify the criteria of the workflow to different criteria? Whether the field will be updated
or not in schedule date?
It won't fire. To fire wf2 we should enable 'Re-evaluate Workflow Rules' checkbox of the field
update which is there in wf1.
If the criteria of the record meets then by clicking on submit for Approval button user can
submit the record for approval (Note: Approval history related list should be displayed on the
record detail page)
Before creating the Approval Process, we should select the object after that we should follow
below steps -
Select the email template (If we don't select any email template salesforce by default send an
email notification to the target approver else with our selected email template target approver
will be notified)
Select the users who can submit for the approval (If we do not select any user by default all the
users who can access to that record can submit)
Initial submission actions ( after submitting the record for approval immediately whatever the
actions included in the initial submission actions section will be triggered)
For each and every step we can see 'Approval actions' and 'rejection actions' sections where we
can add actions to be performed
If the Approver approves the record then actions which are under 'approval actions' section will
be triggered
Final approval actions section (If all the steps approved then actions which are under 'final
approval actions' section will be triggered)
Final rejection actions section (If any one of the step rejected then actions which are under
'final rejection actions' section will be triggered)
Recall approval actions ( After submitting record for approval if you want to revoke we click on
recall approval action on the detail page, after clicking on that button actions which are under
recall approval actions section will be triggered )
14. Scenario: After activating the approval process, I want to add one more step. Is it
possible?
It’s not possible, to add one more step deactivate the approval process and clone the
deactivated approval process and add the new steps.
We can do limited functionalities with work flow where as we can do more actions using
process builder
a. throw work flow we can update only parapet and same record fields but in process
builder we can update child records as well
b. throw workflow we can send out bound msg but we can’t do this in process builder
c. we can’t call apex method in work flow, but we can call apex method from process
builder for this we need use @invokable
d. we can call flow and other process builder from other process builder, but we can’t do
this from work flow
on long run , if we we will concouter more workflows and process builder . So the
metadata of object will become huge , to read large metadata file it will take more
time .for each workflow process builder it will again loads the metadata file so the time
of process will become more . So We are converting all workflows to process builder
and triggers. Workflow solution or process builder solution will be good if it is for core
feature. else tigger is best option .
1. What is Report?
Matrix (we can summarize the information in two dimensional manners, both rows and
columns)
Join (we can summarize information in different blocks on the same object and the related
objects)
5 blocks. ***
4. How many maximum groupings we can do for summary, matrix and join reports?
3 groupings
An Analytic snapshot help us to create report on historical data. It is called” Report Snapshot”.
Any language which supports the following concepts are called opp's based languages.
Apex supports all the above mentioned concepts so Apex is an opp's based language.
Scope of the non-static variables or methods is within the scope of the same object.
Static variables and methods, we can directly call with class name (we cannot access static
variables and methods with object name).
Collections
1. What are the types of Collections available in Apex?
List
Set
List is ordered.
Set is unordered.
We can process records which are stored in list using DML statements (insert, update, delete
and undelete).We cannot process records which are stored in set using DML statements.
No limit for the size of a list. It only depends on the heap size which is 6 MB (Synchronous) and
12 MB (Asynchronous).
countryISTCodeMap.put('India','91');
countryISTCodeMap.put('USA','001');
Clear().Clone(),put(key,value),size(),Containkey(key),get(key),remove(key)isEmpty() etc..
Insert
Update
Delete
Undelete
Number of DML statements per transaction: 150 (as a whole including insert, update, delete
and undelete)
3. What is SOQL?
We can write query on one object while querying on those objects we can fetch the child object
info. Or parent object info. (We cannot capture UN related objects info.)
https://developer.salesforce.com/blogs/developer-relations/2013/05/basic-soql-relationship-
queries.html
Child to Parent Query:
SELECT LASTNAME, ACCOUNT.NAME FROM CONTACT
Parent to Child Query:
SELECT Account.Name, (SELECT Contact.Name FROM contacts) FROM Account
Inner Join:
SELECT Name, (SELECT Contact.Name FROM contacts) FROM Account WHERE Account.Id
IN (SELECT Contact.accountId FROM Contact)
4. What is SOSL?
SOSL Purpose: We can search for a value in multiple objects (no need of any relationship).
insert/update
Database.insert/Database.update
Assume that you are inserting 100 records. If any one of the record fail due to error, then entire
operation will fail. None of the records will be saved into the database. With insert/update if we
use try-catch then we can capture only one error which will cause to stop the operation
Assume that you are inserting 100 records. If any one of the record fail due to error then it will
perform partial operation (valid records will be inserted/updated) if we use
Database.Insert(list,false)/ Database.update(list,false).
6. There is a Queue with name MyQueue. How to query it using SOQL query from the
database?
Queues will store in Group object. To query for MyQueue from the database using SOQL, we
should use the following syntax -
Group grp = [select Id, Name from Group where Name = 'MyQueue' and Type = 'Queue' Limit
1];
Apex Triggers
1. What are the trigger events?
Before Mode: Before the record is saving into the database, it will fire.
After Mode: After the record is saved into the database (doesn't commit at this point of time), it
will fire.
Before After
before insert after insert
before update after update
before delete after delete
After undelete
Note: before undelete event is not available.
2. What are the trigger context variables?
To capture the runtime information we use trigger context variables.
Below context variables will return either true or false.
Trigger.isBefore (returns true if the trigger context is Before Mode)
Trigger.isAfter (returns true if the trigger context is After Mode)
Trigger.isInsert (returns true if the trigger context is Insert)
Trigger.isUpdate (returns true if the trigger context is Update)
Trigger.isDelete (returns true if the trigger context is Delete)
Trigger.isUndelete (returns true if the trigger context is Undelete)
Trigger.isExecuting (returns true if the apex class method is getting call from Apex Trigger)
Below context variables will store records at runtime.
trigger. Old (stores history (old versions) of the records.)
trigger.oldMap (stores history (old versions) of the records along with id.)
trigger. New (stores new version of the records.)
trigger. newMap (stores new version of the records along with id.)
3. Availability of trigger.old and trigger.new for the different trigger events?
Apex Trigger Collections availability for the different events -
Events trigger.old trigger.oldMap trigger.new trigger.newMap
before insert ✘ ✘ ✔ ✘
after insert ✘ ✘ ✔ ✔
before update ✔ ✔ ✔ ✔
after update ✔ ✔ ✔ ✔
before delete ✔ ✔ ✘ ✘
after delete ✔ ✔ ✘ ✘
after undelete ✘ ✘ ✔ ✔
To avoid this error, we should perform DML operation on standard/custom object records in a
different transaction.
In general all the apex classes and apex triggers execute synchronously (execute immediately).
To execute logic asynchronously keep the logic in an apex method (in a separate apex class, not
in same apex trigger) which is decorated with @future annotation.
Note: To analyse the code copy it and paste it in notepad for the convenience.
public class TriggerUtility {
/*
1. Following future method execute asynchronously (whenever server is free it will execute in
future context).
2. We should not declare @future method in Apex Trigger.
3. @future method should be always static.
4. @future method accepts only primitive data types (Integer, String, Boolean, Date, etc...) as
parameters and it won't accept
non-primitive data types (sObject,Custom Objects and standard Objects etc.. ) as parameters.
5. @future method should not contain return type. Always it should be void.
6. From an apex trigger we can make only make asynchronous call outs. To make call out we
should include "callout = true" beside the future @annotation.
7. We cannot perform synchronous call outs from Apex Trigger.
*/
//Below is the example for the future method -
@future(callout = true)
public static void processAsync(primitive parameters) {
//Logic to insert/update the standard/custom object.
}
}
9. Following Custom Objects are available in the organization -
ChildObject__c
ParentObject__c
Click to see the full question.
Relationship between ChildObject__c and ParentObject__c objects is Lookup relationship.
In case of lookup relationship if we delete the parent object record in child object only the
relationship field value will be removed (child records won't be deleted).
But client has a requirement to delete the child object records. How to achieve this?
We should take before delete event. If we take after delete relationship will broke up b/w parent
and child object records.
11. There is a validation rule which will fire if amount = 100 and will display the error
message. There is a workflow rule which will fire if amount > 100 and will update amount
field to 100. One of user saved the record by giving value as 1000.
What will the value of the amount field?
Validation rules will fire first then workflow rules will fire. So, the answer is 100 (Even though
there is a validation rule because of the workflow rule it will accept 100 in the amount field).
12. There is a before trigger which will fire if amount = 100 and will display the error
message. There is a workflow rule which will fire if amount > 100 and will update amount
field to 100. One of user saved the record by giving value as 1000.
What will the value of the amount field?
It will throw the validation error because after the workflow field update before triggers fire one
more time.
Batch Apex
Batch Apex write an apex class that implements the Database.Batcable interface including the following
three methods.
Start Method: Used to collect the records or objects and pass to the execute method.
global (Database.QueryLocator | Iterable<sObject>)
start(Database.BatchableContext BC {}
Strat method returns the Databse.QueuryLocator | Iterable that contains the records or objects pass to
the job.
Iterable: returns 50k records and also enforce salesforce governor limit.
Finish Method: This method is Execute after all batches are processed and will send
confirmation mail which are records are processed successfully
Batch apex default batch size is 200 and maximum batch size is 2000
Apex Code:
Since we are inheriting Database.Batchable interface we should implement all the method
prototypes declared in the interface.
start: It will prepare the records to process and execute only one time.
execute: It will take the records prepared in start method and split those records into batches
and it will execute multiple times. For example if the start method is returning 1000 records
then execute method executes 5 times if you don't mention the batch size (Default Batch Size
is: 200). Maximum batch size is: 2000.
finish: We can perform post commit logic like sending emails with the success or error
information. It will execute only one time.
//at a time we can inherit multiple interfaces but we cannot inherit multiple classes.
//By default batch class is stateless (variable info. store in one method cannot be remembered
in other method),
name += 'start';
//Collects the records to process. It will forward these records to execute method.
//If we use Iterable as return type for this start method it can hold
//If we use Database.queryLocator as return type for this start method it can hold
name += 'execute';
system.debug('@@@Execute Method: '+name);
dept.Location__c = 'Bangalore';
depUPdLst.add(dept);
if(depUPdLst.size() > 0)
update depUPdLst;
name += 'finish';
//Post Commit logic like sending emails for the success or failures of the batches.
mail.setToAddresses(new String[]{a.CreatedBy.Email});
//sendEmail methods
Messaging.sendEmail(new Messaging.singleEmailMessage[]{mail});
//Preparing chron_exp
sysTime = sysTime.addminutes(6);
sysTime.hour() + ' ' + sysTime.day() + ' ' + sysTime.month() + ' ? ' + sysTime.year();
}}
Schedule apex that write an apex class that implement the Schedulable interface.
Sample code:
TaskUtils.remindOwners(opptys);
To schedule the batch class in minutes/hours, in the finish method we should use
System.schedule method which will take 3 parameters Job Name, Chrone Expression and
schedulable class instance name respectively.
//Preparing chron_exp
sysTime = sysTime.addminutes(6);
sysTime.hour() + ' ' + sysTime.day() + ' ' + sysTime.month() + ' ? ' + sysTime.year();
By default batch class is stateless (variable value which is stored in one method cannot be
remembered in another method).
To maintain the state for the batch class, we should inherit Database.Stateful interface.
Scenario: In a set list of emails are stored in execute method. In the finish method that set is
not having any emails. What is the reason?
Answer: By default batch class is stateless. Emails which are added to set can be remembered
only in execute method. If we try to access the set in finish method you won't see those emails.
In finish method if you want to access those emails of that set we should inherit the interface
called Database.Stateful.
Yes it is possible, starting with Apex saved using Salesforce API version 26.0, you can call
Database.executeBatch or System.scheduleBatch from the finish method. This enables you to
start or schedule a new batch job when the current batch job finishes.
For previous versions, you can’t call Database.executeBatch or System.scheduleBatch from any
batch Apex method. Note that the version used is the version of the running batch class that
starts or schedules another batch job. If the finish method in the running batch class calls a
method in a helper class to start the batch job, the Salesforce API version of the helper class
doesn’t matter.
Since @future method and Batch Class both are asynchronous we cannot call future method
from batch class or we cannot call batch class from the future method.
@future method must be static method and can only return void type.
To cover the code for the batch class we should call the batch class from the inside of the
Test.startTest() and Test.stopTest().
Test.startTest();
Test.stopTest();
10. Is it possbile to write batch class and schedulable class in a same class?
Test Classes
1. What is the purpose of writing the test class?
After developing an apex class or apex trigger we should write the unit tests and ensure that we
are able to execute at least 75% of the lines of code.
If you are moving the code from sandbox to sandbox regarding code coverage you won't face
any issue.
If you are moving the code from sandbox to production, you need to include all the test classes
at the time of deployment and salesforce will run all the test classes which you included for the
deployment as well as test classes which are already present in production, if the code
coverage is less than 75% deployment will fail.
we cannot write test code (test methods) inside of the apex trigger.
From API Version 28.0, we cannot write the test methods inside of an apex class which is not
decorated with @isTest.
We can write test methods only in a class which is decorated with @isTest.
Note: We have a governor limit for the overall Apex Code size of the organization which is of 3
MB. If we decorate a class with @isTest annotation Apex Code Size governor limit will be
bypassed.
3. Syntax of testMethod?
@isTest
private class MyTestClass {
By default, test class cannot recognize the existing data in the database.
if you mention @isTest(seeAllData = true) then test class can recognize the existing data in the
database.
From a List Custom Settings, we cannot fetch the existing data without seeAllData = true in test
class.
Suppose you have a custom object called 'CustomObject__c' and it contains many records, we
cannot fetch the existing data without seeAllData = true in test class.
Note: It is not recommended to use seeAllData = true for a test class. Based on the existing data
in database code coverage will impact.
Test.startTest() and Test.stopTest() maintains fresh set of saleforce governor limits. Assume
that you are consuming 99 SOQL queries outside of Test.startTest() and Test.stopTest() then if
you include any SOQL inside of Test.startTest() and Test.stopTest() count will start from 1.
Per testMethod we can use Test.startTest() and Test.stopTest() only for one time.
To execute asynchronous methods synchronously we can call those methods from inside of
Test.startTest() and Test.stopTest().
6. What is the purpose of system.runAs()?
By default test class runs in System Mode. If you want to execute a piece of code in a certain
user context then we can use system.runAs(UserInstance). For more details refer 2nd question
in visualforce category.
system.assertEquals(val1,val2): If both val1 and val2 are same then test class run successfully
otherwise test class will fail.
system.assertNotEquals(val1,val2): If both val1 and val2 are not same then test class run
successfully otherwise test class will fail.
system.assertEquals(val1> val2): If the condition satisfied then test class run successfully
otherwise test class will fail.
Sometimes we cannot satisfy certain if conditions for the apex classes, in those situations on
those if conditions we can add Test.isRunningTest separated with or condition. Example:
if(condition || Test.isRunningTest())
Sometimes in test classes we need to access a variable from Apex Class, if it is private we
cannot access for that we will replace private with public. for this reason we are compromising
the security. To avoid this before the private variables in apex class we can include @TestVisible
so that even though variable is private we can access from the test class.
@Testvisible-- Use the TestVisible annotation to allow test methods to access private or
protected members of another class outside the test class. These members include methods,
member variables, and inner classess
For example
// Private method
// Do something
@isTest
Integer i = TestVisibleExample.recordNumber;
System.assertEquals(1, i);
TestVisibleExample.updateRecord('RecordName');
We should not depend on the existing data in the database. We should create the test data for
all the possible scenarios. Note: Profiles and record Types cannot be created programmatically,
we can query from the database. For the remaining objects including users we should create
the test data.
While testing apex triggers and batch classes, we should do bulk testing at least with 200
records.
Visualforce Basics
1. Visualforce Basics.
Previously Visualforce Pages were not there, instead S-Controls were there.
S-controls have been superseded by Visualforce pages. Organizations that haven’t previously
used s-controls can’t create them. Existing s-controls are unaffected, and can still be edited.
S-controls: It is a combination of HTML and S-control but with this to achieve saelsforce look
and feel, it is very difficult and consume lot of tags.
Visualforce: With visualforce we can easily achieve the salesforce look and feel by consuming
very few tags.
Browsers (IE, Chrome, Firefox, etc...) can understand only HTML, Visualforce will be converted
to HTML before display on the browser by salesforce.
2. What is the difference between system mode (system context) and user mode (user
context)?
Note: to apply security for Apex Class, we can use with sharing while declaring the class. With
sharing will apply only Record-level security. It won't apply Object-level and Field-level security.
3. What are the types of controllers available for the visualforce page?
Standard Controller
Custom Controller
Note: on a visualforce page, we can use either standardController (attribute name for Standard
Controller) or controller (attribute name for Custom Controller). We cannot refer both at a
time.
StandardController -
We can refer any standard object or custom object in this attribute. At a time we can refer only
one object and we cannot refer apex class in this attribute.
controller -
We can refer any apex class in this attribute. At a time, we can refer only one apex class in this
attribute.
extensions
extensions -
In extensions attribute, we can refer multiple apex classes. We cannot refer standard/custom
objects.
There is no such attribute called standard list controller but in the standardController page if
you mention recordsetVar attribute then that page we can call it as standard list controller
page.
In recordsetVar attribute we can give any name which will hold the list of records of the object
which we mentioned for the standardController.
There is no such attribute called custom list controller but in the controller page if we display
multiple records then that page we can call it as custom list controller.
In controller class, we have to query the records from the database to display the records on
the page.
controller="MainClass"
extensions="ClassA,ClassB,ClassC"
First of all it will give priority for the extensions, in case there are multiple classes referred then
it will give priority from left to right after that only it will check in main controller (either
standardController or controller).
In the above scenario, it will invoke the save method from ClassA.
Creation: In a visualforce page, whenever we use form tag then view state will be created for
the page.
Purpose: Assume that, we need to display the user input form in 3 different visualforce pages.
In first and second pages, user has to fill the information and click on Next button. On the final
page, after filling the form if he/she will click on Save button, which ever the information we
filled in the first and second pages should be also saved. View state will store the information
which is filled in first and second page . To maintain the state of the page, we need view state.
Size: All the variables which we use in controller/extensions classes and expressions which are
declared on the page will occupy the space in view state.
Governor Limits: Maximum size of the View State is: 135 KB.
Page Performance:
Whatever the variables information we don't required to maintain the state while navigating to
other pages those variables we can decorate with transient keyword which won't occupy space
in the view state.
It is recommended to use only one form tag. If there are multiple form tags hierarchy of the
folder structure increases which will occupy more space.
To store the following kind of files and refer on the visualforce page -
images
javaScript/jQuery
CSS Style Sheets
zip files
<apex:page showHeader="false">
</apex:page>
Static Resources can be referred with file name. Documents should be referred with url.
Note: For the standardController no need to include code inside of the Apex Class.
Following severity levels are available -
CONFIRM
ERROR
FATAL
INFO
WARNING
9. What is RecordSetVar?
on a standardController page to display the multiple records we use recordSetVar (without the
support of any extensions class).
dataTable: Display the records without standard salesforce look and feel.
pageBlockTable: Display the records with standard salesforce look and feel.
1000
12. How to display more records beyond the supported limit on the VF page?
For the page tag we can enable readOnly attribute value as true so that -
13. What is the difference between input Text and input Field?
input Text: Always display the field as text box irrespective of data types (Checkbox, Picklist,
Look up).
input Field: Display automatically according to the fields data types.
Note: We cannot refer primitive data types (String etc.) with input Field.
14. What is the difference between output Text and output Field?
output Text: Always display the field value as text irrespective of data types (Currency, Look up,
URL etc.).
If it is currency, then it will append currency symbol while displaying on the page. If it is look up
type then it will display as a link.
15. What is pagination and what are the ways to achieve it?
Assume that we need to display 100 records on the page. If the requirement is to display only
10 records at a time -
We can achieve the above functionality with Pagination. We can achieve the pagination in two
ways -
Using standardSetController
Wrapper Class is nothing but list of instances of a certain class. Follow the below steps to create
the wrapper list -
Create an Apex Class say 'MyWrapper'(It can be inside/outside of the controller class.)
If you want to display checkboxes along with records so that upon selecting checkboxes
corresponding records can be processed (Updating, Deleting, etc.).
If you need to display records in single table by combining the columns which belongs to
multiple objects.
Custom labels are custom text values that can be accessed from Apex classes or Visualforce
pages. The values can be translated into any language Salesforce supports. Custom labels
enable developers to create multilingual applications by automatically presenting
information (for example, help text or error messages) in a user's native language.
You can create up to 5,000 custom labels for your organization, and they can be up to 1,000
characters in length.
Where to use?
Visualforce Pages
Assume that you are referring a Record Type Name multiple times in an apex class, in future if
the client asked to rename the record type then in all the palaces we need change by searching
which consume good amount of time. To avoid that if you store the Record Type Name in
custom label and refer that custom label in all the places. If you need to change the name in
future then you need to change only in that custom label.
Assume that you are displaying an error message on the visualforce page, in future if the client
asked to change the error message then it will be a code change. For code change it requires lot
of approvals from business which consume lot of time. If you keep the error message in a
custom label and refer on the page, in future it won't be a code change, in production directly
they can replace the error message in that custom label.
Example: Based on the regions, zip codes should be retrieved. In this case, If you store these
records in a custom object every time we need to query from the database. Instead if you store
the records in List Custom Settings, without consuming SOQL query we can capture the
information from the database.
After that we can check that a particular/current logged in user is part of this custom settings.
Validation Rules
Visualforce Pages
19. What is the difference between List Custom Settings and Custom Object?
Custom setting to create and manage custom data at the organization, profile and user level.
Custom setting data can be used formula field, visualforce, apex and Force.com web service
API
List: List type is a reusable set of static data that can be accessed across your organization.
Hierarchy: You can add the data for the user, profile and organization leve.
No need to use SOQL query to fetch the records. We need to use SOQL query
to fetch the records from the database.
Limited data types are available when compared to Custom Object. All the data types will
be available.
We cannot create validation rules and apex triggers on List Custom Settings. We can
create.
20. What is the difference between rendered, rerender, renderAs and contentType?
rendered: Accepts true or false. If it is true then component will display on the page, if it is false
then it won't display on the page.
renderAs: Used in page tag, We can display VF page in PDF format if we give renderAs = "PDF".
contentType: Used in page tag, we can download VF page in MS Word/Excel etc. based on the
input to contentType.
21. What is button overriding?
Assume that you are displaying inline VF page on Account record detail page. VF page should be
standardCotnroller to Account Object.
Whenever we click on Back or Cancel button on a VF page if there are mandatory fields then we
will see the error messages saying to populate those field values.
24. What are the parameters and how many ways we can pass the parameters?
¶m2=val2 : To add multiple parameters, each parameter should be separated with &
symbol.
From pageReference: Upon calling an action method while returning pageReference we can
append parameters. See the below example -
nextpage.getParameters().put('param1','val1');
nextpage.getParameters().put('param2','val2');
Assume that there are three VF pages which are using the same Apex Class. In this case no need
to pass the parameters from one page to other to hold the information.
Assume that there are three VF pages which are using three different Apex Classes. In this case
to hold information from one page to other, we should pass teh parameters.
We cannot override Save button. When you are on record edit page upon clicking on Save
button if you want to navigate it to a specific url then we need to append saveURL=someURL
parameter to the URL. You will come to this edit page if you click on 'New' or 'Edit' button which
can be overriden with VF page, from this page you can pass saveURL parameter to edit page.
When you are on record edit page upon clicking on Cancel button if you want to navigate it to a
specific url then we need to append retURL=someURL parameter to the URL.
We can use only controller and extensions attribute for the VF component. standardController
cannot be used.
When to use VF Component?
If the VF page logic is huge and if you want to split into different pieces.
Get Request: Whenever we click on a link or button or directly hitting the url in address bar we
can open a VF page.
Postback Request: On a VF page after populating fields if you click on save button certain action
will invoke it is nothing but postback request.
28. What are the types of Ajax Functions in VF page and what is the usage?
actionSupport
actionStatus
actionFunction
actionPoller
actionRegion
ActionPoller: Timer send an Ajax request to the server according time interval that you specify,
the update request can either full or partial page update.
Example:
{ Return count;}
Page:
<apex:page Controller=”ActionPoller”>
<apex form>
</apex:form>
</apex:page>
<apex:page Controller=”ActionPoller”>
<apex form>
</apex:form>
</apex:page>
ActonFunction: ActionFucntion is a component that call the controller action method using
JavaScript.
Syntax: <apex:actionFunction name="callfind" action="{!searchAndfind}" reRender="a" />
Salesforce Lightning :
Lightning is the collection of tools and technologies behind a significant upgrade to the
Salesforce platform. Lightning includes:
Experience: A set of modern user interfaces optimized for speed. This includes the Lightning
Experience, Salesforce1 Mobile app and template-based communities.
Lightning Component Framework: A JavaScript framework and set of standard components that
allow you to build reusable components to customize the Lightning Experience, Salesforce1
Mobile app and template-based communities and build your own standalone apps.
Visual Building Tools: Drag-and-drop technologies for fast and easy app building &
customizations. Use the Lightning App Builder to customize the Lightning Experience and
Salesforce1 Mobile app. Use the Community Builder to customize template-based
communities.
Lightning Exchange: A section of the AppExchange where you can find 70+ partner components
to jumpstart your development.
Lightning Design System: Style guides and modern enterprise UX best practices to build pixel
perfect apps that match the look and feel of the Lightning Experience and Salesforce1 Mobile
app.
What are the challenges you have faced with your lightning components ?