All you need to know about creating reports in salesforce

Salesforce gives a powerful option for generating reports on the data stored within salesforce in custom and standard objects. The wealth of information can be filtered, grouped sorted using reports. The data displayed on the reports is as per the user security access. Reports are stored within folders. A user can run the report if it has access to the folder where report is stored. In this post we will see how to create custom reports in salesforce, different report formats, and other features of reports that are available for usage.

creating reports in salesforce

A report is a list of records which meet your defined criteria. Records are displayed in rows and fields in columns. Reports can be filtered, grouped or ordered as per the business requirements. Reports are to be stored in folders which can be public, hidden, or shared and can be read only or read write type. Folders access can be controlled using roles, permissions, public groups and license types. Before building a report an important think to consider is "Report Type". Once you have finalized the requirements you need validate whether you have a report type that suits your requirements.

Report Type:
creating reports in salesforce needs that you identify your requirements and then determine the report type for it. Report type is a skeleton using which reports are to be built. Custom report types let you to create a new framework in the report wizard, using which administrators can build and customize reports as per needs. Reports type defined which fields are available for use in a report. 

There are two type of report types that is the standard report or the custom report. Standard report types gives access to most of the standard objects while custom report types gives access to custom objects and custom views of standard objects. While creating a new report you need to select a report type and then start building the report. 

Depending on how your report type is structured you will have options to drag fields on to your report. In report type you need to define the primary object and related object fields which you will need while building the report. A report will display records that meet the criteria set in the report type hence it is important to create proper report type before building the actual report. Salesforce also provides lots of standard report types which can be used in building new reports.

To create a new custom report type you need to:
>> Navigate to set up, and search for Report type under create.
>> Click onNew Report Type

creating reports in salesforce

>> Then need to select th primary object that you need for your report, give in description, name, category for the repprt type and click next.

>> The next step is to define the records set that is defining your related objects and then click on save.

how to make reports in salesforce: 

creating reports in salesforce

Before building a report you need to define your requirements, identify the objects which will be needed for building the report, check if there are any standard report types that provides all the objects needed, if not create a new report type and start building the report. Next thing will be define the filter criteria, group, order as per requirements. A user needs to have Create and Customize Reports AND Report Builder permission in order to create, delete or customize reports.

For creating reports in salesforce follow below steps. 

>> Go to Reports tab , select report type depending on your needs and click create

creating reports in salesforce

>> You need to select the type of Report you want to build that is you need to select the report format, this will depend on what your requirements are. There are four different format of report that you can have and those are tabular, summary, Matrix and Joined reports. A Section below has all the details about each of the report types.

>> Next thing to do within report builder is setting the criteria for displaying the records. Here you can select date range for different date fields of the object. Also you can drop fields in filter criteria area and build your own criteria for which you can use different logical operators as well.

creating reports in salesforce

>> Next thing that you can do is group your data either in rows or columns in case of summary, matrix or joined reports
>> Next you can run report to see if it working as per your needs and then save the report in desired folder.

While above are basic steps in building reports in salesforce you can customize your reports using other things like bucket fields, summary fields, subtotaling, smart totaling, joining reports using joined reports, building dashboards using the reports (except for tabular format).

While creating reports you need to select the format of the report. Below are the different Types of Reports and their details.

creating reports in salesforce

1. Tabular.
Tabular report format is a simplext of all and very easy and fast to build. As its names suggests it a simple tabular display of record just like a spredsheet. Its a simple way at looking rows of records with ordered set of fields in columns. Tabular reports give a simple subtotal at the end of the report. These type of reports canot be used for grouping of data or for dashboards.

2. Summary:
Sumamry reports are similar to tabular reports but these allow grouping rows of data. Also you can view subtotals and you can create charts in this type of reprots. Unlike tabular reports you can use summary reprots as source for building dashboards. If yu dont use grouping in this reports it looks exactly same as tabular report.

3. Matrix:
Matrix reports are little enhanced and are similar to summary report with a difference that you can summarize on both rows as well as columns. Like summary reports this can also be used as source for building dashboards.

4. Joined Reports:
Joined reports are the most enhanced ones and were incorporated the last in the list of report formats. With joined reports you can have multiple report blocks that gives different view of data. Each block here acts like a separate sub report with its own fields, columns, filtering and sorting. A joined report can also contain data from different report types.

You can change an already saved report format but that may impact few things and you need to go through the salesforce documentation before you change the format.

Bucket Fields:

creating reports in salesforce

Bucket field in salesforce reports helps you quickly categorize records without having to create new formula or custom fields. With bucket field you can define multiple buckets which can be used to group report values. To build a bucket field you need to drag the bucket field on report and then define the bucket values as per need.

All you need to know about creating an email template in salesforce

email templates salesforce
Every firm needs to have email templates designed so that communications are properly managed. Email templates assist an organisation to deal properly with the leads,users and contacts of the accounts. Email templates properly branded are essential for creating long term and lasting impacts on the recipients. Emails should be readable and at the same time should be able to reflect the companies brand when sending emails to people outside of the organisation.

Using templates can save time and help in standardising the emails that are sent. In salesforce you can create your own templates or use the ones already created by other users. You can also use the sample templates provided by salesforce. To send an email you can go to the record, open the activity tab and then click the email tab. Select the template you want, preview the content, edit as needed and send the mail.
Email template in salesforce allows to create predefined email templates that can be sent to contacts, leads and others. To create new email template you need to navigate inset to >> Communicate Templates >> Email Templates >> Click on New Template

email templates salesforce

There are four different types of email templates that can be created in salesforce. Below are the four types:
1. Text
2. HTML using Letterhead
3. Custom without using Letterhead
4. Visualforce

These are plain text emails which can be sent to those who cant read HTML and prefer plain text emails. These can also include merge fields. To include merge fields you need to select the object first and then the field , this gives the merge field expression which is to be copied in the email template body as seen in below screenshot. All users have the ability to create or modify an email template.

In order to create an HTML templates based on letterhead user needs to have "EDIT HTML Templates" permission on the profile. The look and feel of this type of template is defined by the letterhead used. Logo, colour and text are inherited from the letterhead of the template.

email templates salesforce

While creating a new HTML letter template you need to select a existing letterhead and also need to use proper email layout as per your needs. The folder where you want the template to reside has also to be selected.

email templates salesforce

Custom HTML :
User need to have "Edit HTML Templates" permissions in order to create custom HTML templates. This kind of template is to built with HTML so you need to know the HTML or obtain the HTML code and insert it in the body. In this case you need not use pre existing letterhead and need to build the whole template using HTML

Visualforce Templates:
This type of email templates can be created by administrators and developers. This type of email templates allow for advanced merging and can contain data from multiple records. Sending mass email using visualforce email template is not allowed. Visualforce email template allow for dynamic content like recipient location or type, it also has multilingual support. Visualforce templates allow dynamic attachment based on salesforce data.

email templates salesforce

The visualforce email template content has to be written with in components <messaging:emailTemplate> </messaging:emailTemplate>. There are other components that has to be used for writing the either plain text or HTML body. Component for including attachments, email header.

Note below things while creating an email template in salesforce.
1. You need to mark the template as Available for Use else you wont be able to use it for communication.
2. You can send test mail to user, related record or an email id to test the mail and check for merge fields.

email templates salesforce

Text, Custom HTML, and Letterhead email templates can be used in Lightning Experience however you cant use visualforce email template in Lightning experience.

Considerations while using salesforce classic templates in lightning experience.
- In order to display classic email templates you must include templateId field in the lightning email action layout.
- Attachment are read only in lightning experience and cant be added or removed.
- Externally Linked CSS files are not supported.

Text Emails: Both subject and Body can be edited.
Custom HTML Template:  You cant edit the subject or body
Letterhead email template: You can edit subject but cant edit header and footer

Salesforce Interview Question and answers for Developers Part 9

49. What is the significance of master detail relationship?
Ans - Master detail relationship can be set by creating master detail field on the detail object. In master detail relationship whenever a master detail record is deleted the detail records are also deleted. When creating a detail record it is mandatory that the master field is populated with a value(i.e master field is mandatory) It is also mandatory that this field is kept on pagelayout. A standard object can never be set as detail object. With master detail relationship roll up summary fields can be created on master object.

50. What is trigger recurssion and how can you you avoid it?
Ans - If an exceting trigger calls itself then it goes to into infinite loop and is called recursion. If a trigger on a particular object executing on a particular dml does the same dml on that object then the same trigger would be called and it will go into recursion. A static variable can be set in a class before executing the trigger to avoid the recursion.

51. What is an external id?
A external id is field that can be used as a reference while updating records. If the data is coming from an external system then the unique field that the external system has could be used as an external id within salesforce. External id can be used while upserting records within salesforce using data loader. There is a limit on the number external ids you can have in an object.

52. What are governers limit and what is its significance?
Ans - Governers limit is a limit that salesforce enforces on every code execution so as to avoid monopoly by any single org. Since the resources are shared across organisation governer limit checks on the resource utilisation. Number of limits are imposed limit 100 soql query exception, 50000 rows can be fetched using soql etc

53. Why one should not put a soql or a dml within for loop?
Ans - Putting soql or dml in for loop can easily hit the governer limit hence we should not put them in for loop. Only 100 soql are allowed in one transaction and only 150 dmls are allowed.

54. What are the various collections available in salesforce?
Ans - In salesforce along with primitive data types and sObjects there are collections. Apex uses following collections as below
    List - stores duplicate values which are ordered.
    Set - stores unique values which are unordered
   Map - consists of keys and values

Salesforce Developer Interview Question and answers part 8

 Next>>> Part 9[Questions 49-54]

43. What is the significance of ID data type in salesforce?
Ans - Every record in salesforce is represented using a parameter called as id. Salesforce uses Data type ID for storing such record id's. An ID is represented in terms of 15 digit or 18 digit. 15 digit id is case sensitive where as 18 digit id is case insensitive. First 3 characters of ID indiacte the object for example 001 means its an account record or 006 means its an opportunity record.

44. What is the difference between a List and Set?
Ans - A List and Set are both collections similar to array with following differences
 List can store duplicate values in it, set can store only unique values
List can store primitive types,sObject as well as collections in it,Set can store primitive and sObjects but not collection
List is Ordered where as set is unordered.

45. What are the various primitive data types available in salesforce?
Ans - Various primitive data types in apex include following
  Decimal, double, integer, Long, String, Id, date. datetime, time, currency, boolean

46. What is a map collection? and how is it different from list and set?
Ans - A map consists of key and values. Keys are unique while values can be duplicated. Every key points to a value. Using methods we can retrieve the values using the keys or store key-values mappings. map is useful in storing relationships between to parameters. Key is similar to set which can only store primitive types where as values are like set that can also store collections in it. There are number of methods that can be used to manipulate data in map.

47. What is an sObject data type?
Ans - sObject is a data type that can store standard or custom object in it. Account for example is a sObject type of data.
ex-   sObject sO = new account()

48. What is a sandbox.? what are the different types available?
Ans - sandbox is a test environment used for developing or testing the functionality. It is an exact copy of your production org. Sandbox can be full sandbox, Developer sandbox, Developer Pro, Partial Data sandbox

 Next>>> Part 9[Questions 49-54]

Salesforce Developer Interview Question and Answers For Developers Part 7

37. What are the various ways of deployment in salesforce?
Ans - Metadata components in salesforce can be deployed using various ways as below
         Change set, Eclipse IDE, ANT, Workbench
38. What is an account team?
Ans - Account team is group of users that work on a articular account. The users in a account team can be given access depending on the need. A account team appears as related list on account.
39. How to override a custom button on object with a visualforce page?
Ans - Inorder to override a button with a visualforce page the page needs to use standard controller of that obejct. For example a account button can be overriden with visualforce page provided the page uses account standard controller.
Ex   <apex page standardcontroller ="Account">
40. What are various email templates types available in salesforce?
Ans - Email templates used in salesforce could be text, html, custom html or visualforce type

41. What is the difference between rendered and rerender in visualforce page?
Ans - rendered can be used to hide or show a particular section of the page. It is mapped to a boolean variable that can set which shows or hides or executes that section or component. Rerender is used to refresh a section or component of the page. In Rerender the ids of the section need to be specified comma separated.
42. How can you expose a apex class as web service? and how to obtain a wsdl file for exposed class?
Ans - In order to expose a class as a webservice we have to use keyword 'webservice' with the method also the method should be global and also the class should be defined global. ex-
Global class webClass{
 global webservices void mymethod(){
A wsdl file for a apex class can be obtained by using the button generate wsdl on class.

Next>>>Part 8 [Questions 43-48]

Salesforce Interview Question and Answers For Developers Part 6

Next>>> Part 7 [Questions 37-42] 

31. What are custom controllers?
Ans - Custom controller is nothing but a apex class that associates itself with a visualforce page that does not use any standard controller. All of the visualforce functionality is custom defined and no standard page functionality is directly available. In a visualforce page the custom controller is defined by keyword controller. ex <apex page controller ="mycustController" >

32. How can standardcontroller functionality be extended?
Ans - This can be done using associating a class using extensions.

 33. Can a visualforce have more than one extenssions?
Ans - Yes, a standard controller can have more than one extension.
34. How can you place an entire visualforce page in another visualforce page?
Ans - This can be done using attribute include. We have to just specify the name of the visualforce page and include this attribute in our visualforce page.

35. What are various standard exceptions that salesforce throws?
Ans - salesforce throws number of standard exception . Some of the important ones are as below-
 dmlexception, listexception, email exception, calloutexception, JSONexception, mathexception, Queryexception, sObjectexception, xmlexception, typeexception, visualforceexception, stringexception, searchexception, nullpointerexception, noaccessexception,

36. What is the significance of profile?
Ans - A profile is associated with a user. Every user will have a profile. A profile is used to define a user's permission to do various functions within Salesforce. A profile controls various permission as below, (Object permissions, tab,record type, report type, application permission, visualforce pages, classes, login hours, ip ranges from where user can log in, field permission, pagelayouts

Next>>> Part 7 [Questions 37-42] 

Salesforce Interview Question and Answers Part 5

Next>>> Part 6 [Questions 31-36]

25. What is a workflow rule?
Ans - A workflow rule is a set of actions that can be executed when a record is created or edited. A workflow rule consists of criteria when a workflow rule is executed and actions. Criteria when a workflow rule gets executed could be either of the following,
  • Created
  • Created and every time it’s edited
  • Created, and every time it’s edited.
Actions could be field update, task assignment, email alert or outbound messages. These Actions could be immediate or time dependent. 

26.  What is an approval process?
Ans - An approval process is a process which can be used to approve records . An approval process consists of steps necessary for a record to get approved/rejected, user who must approve it or reject it. Approval process also specifies what actions to be taken when a record is approved, rejected or rejected.

27. What is the difference between Role and profile
Ans - Role determines what record is visible to a user while a profile determines what actions they are allowed to perform on that object. That is, we can say that profile defines Object level access, field level access while Role defines Record level access. Profile is used give access to Tabs, fields via FLS, General and Administrator settings. Role hierarchy can be maintained, this gives access to records in hierarchy manner.

28. What is data loader and what can be done using data loader?
Ans - Data loader is tool that can be used to extract salesforce data and also insert/update salesforce data. Data loader can also be used for bulk data delete,insert or update. It uses api for operation. Some of the features of data loader are as below
  • Drag-drop field mapping
  • Standard as well as custom objects are supported
  • Provides success and error log files in CSV format
  • Supports insert, update, delete, extract data operations
29. What is lead conversion?
Ans - A lead conversion means transition of a prospect into an account, contact and a possible opportunity. Technically a lead record when converted creates an account record, a contact record and optionally an opportunity record. There is also a provision to create task. A converted lead cannot be accessed from salesforce UI. 

30 . What are analytical snapshot?
Ans - Analytical snapshots can be used to schedule a report run and then save the report result as records in custom object. While building a analytical snapshot we have to select a source report and destination object. Then map the fields from report and object. The report runs at specified time and then inserts the report result as records in that object. Advantages that we get through analytical snapshot are as below, Runs reports faster, Sot and filter data using list views, can view trend in data via object records. The object selected for record insertion should not have any insert trigger on it.

Next>>> Part 6 [Questions 31-36]

Salesforce Interview Question and Answers For Developers Part 4

Next>>> Part 5 [Questions 25-30]

19. What is territory management
Ans - A territory is a collection of accounts and user where in minimum read access can be given to the account. Territory management is nothing but account sharing mechanism based on account data. Territory management affects account and objects that have master detail relationship with account.
Territory management gives and ability to expand sharing model based on account data. A territory can have multiple users, also a user can present in multiple territories. Criteria based on account data can be set, and based on that criteria access level can be set for the users under that territory.

20. What is apex sharing?
Ans - Like manual sharing using configuration, records can also be shared using apex. Every object has associated share object where records can be inserted to share records with group or a user. For example account has accountshare, case has caseshare etc. Record access level, row cause, user/group can e specified while inserting the share records.

21. What is manual sharing in salesforce?
Ans- Using manual sharing rules we can grant wider access to data to a set user. This can only used to give more access and not to restrict access to data. While writing a sharing rule we have to give criteria on which record should be shared(Based on record owner or defined criteria), To whom the record should be shared(Group,role or role and sub ordinate) and the access level(Read only, read/write). Manual sharing is available for some standard objects and all the custom objects. 

22. What is OWD and its significance?
Ans - Organization wide default is used to set default access level for various standard objects and all custom objects. Default access can be set as Public read only, Public read write, Public read write and transfer for different objects. For example if the record access level is set to private then the records will be accessible only to owners, users above in role hierarchy and if it shared using manual sharing. Using OWD we can also set if the records can be set using role hierarchy for custom objects (For standard objects records are always shared using role hierarchy).

23. What is test coverage and what is its significance?
Ans - Apex code written in salesforce needs to tested using test classes. Apex code gets test coverage depending on the logic written in test class. The functionality implemented in an apex class has to be tested using test class. Salesforce does not allow deployment if the entire org has coverage less than 75%.

24. What are standard controllers in visualforce?
Ans - Standard controller when used in a visualforce page gives the same functionality and logic as used for standard pages. For example standard button save functionality will be avaibale as it is and we need not write any method to execute it. Similarly it also gives all the action behaviour and look and feel of the standard object. To specify a visualforce page as standard controller we have to specify standardcontroller="objectname"
 ex- <apex:page standardController="Account"> 

Next>>> Part 5 [Questions 25-30]

Salesforce Interview Question and Answers For Developers Part 3

Next>>> Part 4 [Questions 19 -24] 

13. What is a wrapper class in apex?
Ans- A wrapper class is user defined type. We can set the properties of this type as per our requirement. similar to standard data types we can create collections of the wrapper class too. Wrapper class will be a inner class with a constructor in which the parameters are set. For example a wrapper could be combination of data contained in two different objects. A standard data type always allows to store data which of a single type, so we can say that whenever we have to collect data of different types we have to use wrapper class.

14. Reports in salesforce, what are the different types?
Ans - Reports gives access to the data that organisation has collected over a period of time. Reports return set of records depending on criteria used. Data is displayed as columns and rows. A report can be configured with filter criteria and also grouped and displayed as chart. Reports are stored in folders. Following are the different types of reports available in salesforce
  • Tabular
  • Joined
  • Summary 
  • Matrix
The report can also be extracted as an excel sheet.

15. Dashboards in salesforce, what are the different types?
 Ans - A dashboard displays data in a graphical way using data contained in a report. That is data source is one of the report(summary or matrix), this data can be displayed in a component. Following are the different types of dashboards components available in salesforce
  • Chart(Bar, Line,Pie,Donut, Funnel)
  • Guage
  • Metric
  • Table
  • Visualforce
A dashboard can be viewed as either logged in user(dynamic dashboard) or as a specified user(static)

16. What is a report type?
Ans - A report type is a skeleton over which you can build the report. It specify the structure of your report(Object relationship). Salesforce provides standard report types using which reports can be build. If the standard type does not suffice your requirement then we have to go for custom report type. It allows to build framework from which reports can be created. While building report type we need to select object and the relationship between objects to display in report. Which fields will be available for display can also be set.

17. What is a record type?
Ans - Using record type we can set different page layouts, picklist values and business processes to different users.
A profile can be set with a default record type or the user can be given option to select the record type before creating the record. Record type is can be created for both standard as well as custom objects.

18. What is trigger code?
Ans - A trigger is a piece of code that executes on dml on a particular object. The code can be made to run on multiple events like update, insert, delete, upsert etc but  a particular trigger code will only on single object. If multiple records initiate a trigger code then all of those records are available in list. A trigger code should always be bulkified , that is it should be able to handle all the records.

Next>>> Part 4 [Questions 19 -24] 

Salesforce Interview Question and Answers for Developers Part 2

Next>>> Part 3[Questions 13-18]

7. What are different trigger context variables and what is their significance? 
Ans - Trigger context variable are the various parameters that have information about records that initiated the trigger. They are also the variables that store information about currently executed trigger. Various important context variable are as below
  • - holds list of records that initiated the trigger code
  • trigger.old- older version of the records that initiated the code
  • trigger.isinsert - boolean variable that states whether the trigger is initiated because of insert operation(similarly there are update,delete etc of this type)
  • trigger.oldmap,trigger.newmap,trigger.isupdate, trigger.isafter,trigger.isbefore are some of the other context variables.
8. What are trigger.old and variables?
Ans - These are lists that store all the records which have called the trigger code. holds the newer version of the records while trigger.old is the original version of the records. For example if the trigger is called on update then the will have newer values to be updated while trigger.old will have values that were already existing in the data base. Both of these together can be used for comparing fields values if they are changed.

9. How to catch exceptions in apex?
Ans - Exceptions in apex can be catched using try catch blocks. The code that is susceptible to exception should be put in try block, the thrown exception can be handled in catch block, optionally a final block can also be used(final block is always executed at the end). The catch block takes in parameter which could be generic exception or standard thrown exception(listexception, dmlexception etc) or could also be custom defined exception.

10. What is a developer console?
As - Developer console is framework which can be used to run a anonymous piece of code, it can be used to execute test classes, monitor test coverage and for debugging purpose. It is very helpful in testing, validating the performance , debugging troubleshooting,and executing soql, sosl or any short short apex code on the fly.

11. What is the difference between action function and action support?
Ans - Both action support and function can be used to call a controller method using an AJAX request.
Action function can call the controller method from java script.
Action support adds AJAX support to another visualforce component and then call the controller method.
Action function cannot add AJAX support to another component. But from a particular component which has AJAX support(onclick, onblur etc) action function can be called to call the controller method.

12. What are custom settings?
Ans - Custom settings are similar to custom objects. Custom sets of data can be created using custom settings which can then be referred in apex code, salesforce api, formula fields or validation rules. The advantage of using custom setting is that there is no need to fire query. There number of methods that can be used to extract and manipulate data in custom settings. Types of custom settings include List and Hierarchical custom settings.

Next>>> Part 3[Questions 13-18]

Salesforce Interview Question Answers for Developers Part 1

Next>> [Part 2 Questions 7-12]

1. What is a custom label?
Ans - Custom labels are used to store static string values which can be used coding i.e in apex or visualforce pages. They can also be used for language translation, i.e we can define values in different languages and use them in apex/visualforce pages. There is a limit on the length of the string that can be stored in label.

2. What are the different actions available in workflow?
Ans - A workflow has following actions
Field update - either of the same object or cross object field update(In case of some objects only)
task create - create and assign the task to a user
email alert -  send a email to user or group of user with a selected email template Outboud messages - send field values as outboud message to desired url link

3. What are the different api's available in salesforce?
Ans - The API's provided by salesforce include - SOAP API, REST API, METADATA API, BULK API
SOAP - SOAP API can be used to create, retrieve, update or delete records, can be used with any language that supports web services
REST - Its a REST-based Web services interface for interacting with Salesforce application
METADATA - cab be used retrieve, deploy, create, update, or delete customisations in the salesforce organisation. This can be used in making tools that can manage metadata within the org
BULK - It is based on rest api principle and can be used for loading or deleting large set of data

4. What is a role hierarchy?
Ans -Role hierarchy is a tree that places one role below the other. A role can have many child's but a role can have only one immediate parent. Roles are basically used for setting record level access using OWD. When an object has share records using role hierarchy it means the the user placed higher in role hierarchy will get access to the records owned by the users placed lower in the role hierarchy. Standard objects records are always shared using role hierarchy. It can be disabled only for custom objects.

5. What are different object relationships in salesforce?
Ans -Salesforce objects can be related to each other using following relationships
Look up relationship, Master detail relationship, many to many relationship,self relationship(hierarchical relationship)
Lookup Relationship - This can be created using a simple lookup field on the child. Default settings does not make the field mandatory however it can be made mandatory by setting so.
Master Detail Relationship - This can be set up using master detail relationship field. A master record when deleted deletes the detail records. With this kind of relationship we can create roll up summary fields on master object. Note that a master object can never be a detail object.
Many to many Relationship - this can be developed with a junction object which has two master detail fields to the two objects.

6. What is a formula field?
Ans -A formula field is a read only field that calculates at run time and returns output depending on the expression used in its definition. It is updated every time the source field values are changed. It can have return type as any of the below,
  • checkbox 
  • currency 
  • date 
  • datetime 
  • number 
  • percent 
  • text

    Unable to lock row issue in salesforce

    Unable to lock row is an issue that scares almost every developer thanks to the limited or almost no options left to resolve it or even predict when and where it would pop up. Salesforce momentarily locks the record when it is getting created or updated. This is done so as to maintain data integrity and avoid data inconsistencies. The lock typically lasts for very few seconds or less but could be good enough to cause the row lock issue on other operations happening on the same record.

    While the main purpose of this article is to provide solution on row lock issue; it is very important to understand in which scenarios such an error would occur. This is important because most of the times it becomes difficult to identify how and from where the error is coming.

    Parent Record is locked when the child record is getting inserted or updated.
    - Consider a child record is getting inserted then its parent is temporarily locked for updates and if the same record is then updated manually by a user or through different operation or batch class the record update fails with the row lock error.

    Two child records of same parent are being attempted with an update through bulk update in two different parallel batches at the same time then one of the record fails with the row lock issue as it is already locked because of other update.

    If there are too many detail records for a master record then there is a very high chance that the master record would remain locked and updates on detail records would fail as the master record would remain locked.

    Assynchronous operations like batch apex or future methods can cause the issue while the same records are being update through different operations.

    All in all predicting and preventing this error is a very tough job as the error remains intermittent without a particular pattern and repeatability. Now coming to the main point, lets see what we can do to make sure we reduce the these errors to the minimum.  

    1. If the error is thrown at a particular update or insert dml then we can have a while loop on it and retry it untill the lock is released and successfull update/insert happens.
      We can do this for no of few attempts as otherwise it may becoem infinite loop.

    integer i = 0
      update accList
    catch(exception ex){
       if(ex.geterrormessage() == 'Unable to row lock'){ 
         i = 10;

    2. If the error is thrown during bulk data updates through data loader then try to have serial updates rather than parallel. Or if parallel is used then try to have smaller batch sizes this would reduce the risk of errors.Try to sort out records so that child parent records remain in same batches and are split across multiple batches. These techniques although complicated but if followed would definitely reduce the errors and hence the overall update time.

    3. Try to avoid writing too many future methods that are called from trigger and would perform dml operations on same or related objects.

    salesforce interview Question Answers part 19

    188. How can you prioritize the batch apex jobs pending in the queue.
    Ans: This can be done by reordering jobs from set up -> Apex Flex Queue Or can even be done through apex code.
         We can use FlexQueue methods to do this in apex. Example: moveAfterJob,moveBeforeJob etc

    189. How many records can a SOSL query return?
    Ans: A SOSL Queury can return upto 2000 records only.

    190. How many @future method invocations are allowed per apex transaction?
    Ans: 50 future method invocation are allowed per apex transaction

    191. What is the total heap size limit in case of synchronous and Asynchronous transaction?
    Ans: 6MB in case of synchronous and 12 MB in case of Asynchronous transactions

    192. How can you track the progress of a scheduled job thorugh apex?
    Ans: This can be done query the object CronTrigger which stores all the relevant information like number of times the job was run, next run time etc.

    193. How many scheduled jobs can you have at one time?
    Ans: We can have upto only 100 jobs scheduled in the org.

    194. How can you make callouts in @future methods?
    Ans: this can be done by mentioning callout=true

    195. How can you expose your class for external application as a REST resource?
    Ans: This can be done by using the annotation @RestResource 

    196. When is @HttpPut annotated method calles in case of REST?
    Ans: This method is calles when a put request is sent which creates or updates.

    197. Can a map key hold a null value?
    Ans: Yes a key can be a null value.

    198. What happens when you add a entry that has the key which is already exists in the map?
    Ans: This overwrites the already existing value against that key.

    199. Can you have 2 different keys of type string only differing in case?
    Ans: Yes this is possible as the keys of type string are case sensitive and can have multiple simialr strings differing only in case.

    200. Do test classes count against the apex code limit for the organisation?
    Ans : No classes marked as isTest are not counted against apex code limit.

    201. What is the use of creating remote site settings?
    Ans: A apex callout can succefully call the external site only if it is defined in remote site setting else the callout fails.