Saturday, June 11, 2016

Common interview questions for Salesforce developers

  1. Name three Governor Limits.                                                                                   
    DescriptionSynchronous LimitAsynchronous Limit
    Total number of SOQL queries issued (This limit doesn’t apply to custom metadata types. In a single Apex transaction, custom metadata records can have unlimited SOQL queries.)100200
    Total number of records retrieved by SOQL queries50,000
    Total number of records retrieved by Database.getQueryLocator10,000
    Total number of SOSL queries issued20
    Total number of records retrieved by a single SOSL query2,000
    Total number of DML statements issued150
    Total number of records processed as a result of DML statementsApproval.process, or database.emptyRecycleBin10,000
    Total stack depth for any Apex invocation that recursively fires triggers due to insert,update, or delete statements16
    Total number of callouts (HTTP requests or Web services calls) in a transaction100
    Maximum timeout for all callouts (HTTP requests or Web services calls) in a transaction 120 seconds
    Maximum number of methods with the future annotation allowed per Apex invocation50
    Maximum number of Apex jobs added to the queue with System.enqueueJob50
    Total number of sendEmail methods allowed10
    Total heap size6 MB12 MB
    Maximum CPU time on the Salesforce servers10,000 milliseconds60,000 milliseconds
    Maximum execution time for each Apex transaction10 minutes
    Maximum number of push notification method calls allowed per Apex transaction10
    Maximum number of push notifications that can be sent in each push notification method call
  2. When do you use a before vs. after trigger?
    Before Trigger:
    1. In case of validation check in the same object.
    2. Update the same object.
    After Trigger: 
    1. Insert/Update related object,not the same object.
    2. Notification Email.            

                                                                                                                   
  3. What’s the maximum batch size in a single trigger execution?                                
    200
  4. What are the differences between 15 and 18 digit record IDs?
    Salesforce record Id uniquely identifies each record in salesforcce. Salesforce record Id can either be 15 digit or 18 digit. 15 digit salesforce record  id is case sensitive and 18 digit salesforce record id is case insensitive. Every record in salesforce is identified by unique record Id in every salesforce organization.
    • 15 digit case-sensitive version is referenced in the UI and also visible in browser
    • 18 digit case-insensitive version which is referenced through the API
    The last 3 digits of the 18 digit Id is a checksum of the capitalization of the first 15 characters, this Id length was created as a workaround to legacy system which were not compatible with case-sensitive Ids. The API will accept the 15 digit Id as input but will always return the 18 digit Id.

    In this post I will explain the process to convert 15 digit salesforce Id to 18 digit salesforce Id.
    Visualforce Code:
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    <apex:page controller="idConvertor">
        <apex:form >
            <apex:pageBlock >
            <apex:pageMessages id="showmsg"></apex:pageMessages>
                <apex:pageBlockButtons >
                    <apex:commandButton value="Convert" action="{!convert}"/>
                </apex:pageBlockButtons>
                <apex:pageBlockSection >
                <apex:inputText value="{!inputId}" label="Input Id:"/>
                <apex:outPutText value="{!outputId}" label="Output Id:"/>
                </apex:pageBlockSection>
            </apex:pageBlock>
        </apex:form>
    </apex:page>
    Apex Code:
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    public with sharing class idConvertor {
        public String inputId{get;set;}
        public String outputId{get;set;}
        public PageReference convert(){
            outputId = convertId(inputId);
            return null;
        }
        String convertId(String inputId){
            string suffix = '';
            integer flags;
            try{
                for (integer i = 0; i < 3; i++) {
                    flags = 0;
                    for (integer j = 0; j < 5; j++) {
                        string c = inputId.substring(i * 5 + j,i * 5 + j + 1);
                        if (c.toUpperCase().equals(c) && c >= 'A' && c <= 'Z') {
                            flags = flags + (1 << j);
                        }
                    }
                    if (flags <= 25) {
                        suffix += 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'.substring(flags,flags+1);
                    }else{
                        suffix += '012345'.substring(flags - 26, flags-25);
                    }
                }
            }
            catch(Exception exc){
                ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR,'Please enter Valid 15 digit Id'));
            }
            String outputId = inputId+suffix;
            return outputId;
        }
    }
  5. What is custom setting.Provide an example of when a Custom Setting would be used during development?
    Custom settings are very useful when it comes to storing static or reusable information in Salesforce, plus it also can work as a switch to turn your application rules ON and OFF. For both Admins and Developers, Custom Settings act as a golden child in the Salesforce family. Under the hood Custom Settings are much like Custom Objects and are accessible via their own API, but you can’t have triggers on a Custom Setting and the available field types are more limited. They do count towards your Custom Objects governor limit however.
    There are two types of settings – List and Hierarchical. In this post we are going to look at each of them and suggest typical ways in which you can use them.
    List Custom Settings
    List settings are structured similar to records held in a custom object. They allow you to store org-wide static data that is frequently used, and therefore cached for performance. Data in List settings do not vary by user and profile, there is no ownership, field level security or record security, and it is available organisation wide (i.e. public for all). It’s best used for data lists, especially reference code lists, and great for when you want to convert code values from one system to another or any other mapping or list.

    You may ask why we need to use List settings when same thing can be done through a Custom Object? Well the answer is simple. Custom Settings are stored in the application cache and do not count against SOQL limits when fetched. Also they are much quicker to implement, easier to maintain and they won’t use up one of your precious Custom Tab limits to maintain. They can also only be updated by a System Administrator (or Configure Application profile permission user). Custom Settings have their own methods to access them – we will have a look below at an example on how we can use getInstance() and getAll() methods.
    Lets consider a scenario where your customer Service team wants to differentiate between incoming email address with domain names. They want their partner emails to be redirected to different queue with some additional business logic to be applied. For creating a new Custom Settings go to Setup – Develop – Custom Settings, Click New and enter details.
    pic-1
    Once you have created the custom setting, you need to define the fields to add to it. The following are the data types that are available for custom settings fields.
    Salesforce custom settings
    In the image below we are storing a few email domain names in custom settings and later fetching them via Apex using getInstance() and getAll() methods. The purpose of this list is to allow us to select the correct Partner details based on company’s domain name. By using the custom setting we can quickly find the mappings we need without querying for a matching field on the Account record (where we may have millions of records).
    custom settings
    The following code snippet is an example of one of the ways to use List custom settings in Apex:
    Custom settings Salesforce
    In addition to holding lists of static data, List Custom Settings are also useful for:
    • Holding environment credentials: Webservice endpoints for production, uat, prepod and dev are likely to be different – don’t hardcode them!
    • To hold environment ids: If you have rules, buttons or links that need to utilize specific Salesforce Id values these are going to be different across your environments or may change over time. Rather than hard coding a user or profile id in a Rule, Formula or Apex code you can use a custom setting to hold values such as an ‘Escalation User Id’.
    • To hold environment values: You may have rules about opportunities greater than $100k however this limit make change in the future dur to changes in market conditions. Hold the value in a List custom setting if it applies globally to all users (without question) and you need to reference it in Apex. Hold it in a Hierarchical setting if there’s a chance you need to switch it off by user or profile or have different values, or if you need to access the value in a Workflow, Formula Field or Validation Rule.
    Custom Settings as a Switch
    on / offf
    Hierarchical Custom Settings are defined once and can hold a unique set of values for the Organisation, each Profile or each individual User. Salesforce automatically grabs the lowest level of setting for the running user when a getInstance() call is made, or when accessed in a configuration such as a Validation Rule, Workflow or Formula Field. Note that only Hierarchical settings can be accessed declaratively whereas List settings are for Apex/Visualforce only.
    Using hierarchical settings can provide the functionality of a switch, which you can use as ON or OFF to disable Integrations, Triggers, Workflow Rules, Assignment Rules and Validation Rules for all users, specific profiles or individual users. This is possible when you use hierarchical custom settings with a checkbox field to control your system functions, but you could also use it to control internal debugging log levels for example.
    Using hierarchical settings lets you control down to an individual user for whom it is de-activated, so you can force a data validation rule for some users and disable it for others. For triggers it is even more useful because triggers cannot be de-activated in a production org without carrying out time consuming deployments (once to switch off and then to switch on again), with no guarantee of how long each deployment will take (depending on the instance queues, org usage and number of unit tests in the org to be run each time).
    This becomes especially useful when performing data fixes or data migration, or if needing to disable a failing trigger or Apex functionality in a live org (saving hours in performing the redeployments). Because of the hierarchical nature you can isolate to an individual user, so you could disable all triggers firing during a Data Load for an Admin user to drastically reduce the time to upload data or for an Admin when fixing data errors to switch off emails being sent to customers from Workflows. No more need to deactivate rules one by one and re-activate them when you’ve finished, and work no longer has to always be performed ‘out-of-hours’.
    Below is an example of how a hierarchal custom setting can be implemented. You can add new records as Profiles or individual Users to bypass any Apex Triggers or Validation Rules.
    In this example we create a validation rule to prevent a User from closing a case with any Open activities, and use $Setup.Your_Custom_Setting with an AND condition in our validation rule to switch this off centrally:
    AND
    (
    ISPICKVAL( Status , “Closed”) ,
    ISCHANGED( Status ) ,
    Open_Activities__c <> 0 ,
    $Setup.MP_Global_Settings__c.Fire_Validation_Rules__c
    )
    As you can see if you built all your validation rules, workflow rules and triggers using this technique it is an extremely powerful way of controlling behaviour across the entire application.
    You can set the default Organisation Level value (as seen in image below) to fire all Validation, Workflow, Assignment and Triggers rules for all Users. To bypass any profile or user, add a record in Custom settings. In the example below only triggers will fire for System Administrator Profile and no rules will fire for User Ali Zafar, even though he is a System Administrator because the lowest level of custom setting is applied automatically. Also, note that the user personal settings will override all his other settings.
    Salesforce settings
    This technique can be expanded upon for a number of other reasons:
    • To switch application functionality on/off: Useful for orgs with multiple divisions who want different behaviours. Try to create re-usable settings by function such as ‘Reassign Old Leads to Queues’ rather than generic divisional settings such as ‘Run Marketing Rules’.
    • To control change management: Similar to the above, when implementing a suite of changes where you need to be able to ‘rollback’ the function in the event of an issue, or you wish to soft launch a feature, consider implementing a Hierarchical custom setting to let you test the change in production for a single user or profile before releasing to all users.
    • To provide dynamic page overrides: Different Visualforce or standard pages can be called in a Button or Apex Visualforce Controller based on the Custom Settings for a particular profile or user. This can even be used to include different logos or branding.
    • To extend the Profile with custom attributes: Profiles cannot currently be extended with custom fields, so use a Hierarchical Custom Setting to define the fields you need to add at a Profile level. For example, a Sales Commission % field which is used in a formula field. This can then be further overridden by individual user and potentially saving on Profile proliferation!
    • To switch Visualforce components on/off: Users can hide sections on Page Layouts but they can’t hide sections on a Visualforce page (ok they can collapse the section but it isn’t remembered between sessions). You can create “Show Financials”, “Show KPIs”, “Show Case History” checkbox options to switch this data off on Visualforce pages using the Rendered attribute to control visibility. Useful when you don’t want to hide the data completely through Field Level Security, just simplify the pages, and very useful for showing different features to Community users by Profile or User and even saving results by user to collapse or hide sections.
  6. When should you build solutions declaratively instead of with code?
    Here are some use cases and examples for functionality that can easily be build declaratively, without writing a single line of code:
    • Instead of writing Triggers, we can automate Field Updates using Workflow – automatically populating a field with a default value or updating a field based on the value of another field is a pretty common requirement. Workflow can address the basic use cases just as well as writing an Apex Trigger.
    • Use Formula Fields and Roll-Up Summary Fields for field calculations instead of writing a Visualforce page and calculate the field values in a controller extension – a good example is a simple Order Management app. On the Order Lines, the order line total is calculated by multiplying the item price with the ordered quantity. A formula field can easily achieve this. And if we want to have the sum of all order line totals on the order header, we can use a Roll-up Summary field, as long as there is a Master-Detail relationship between the order and the order lines object.
    • Enforce Business Rules with Validation Rules whenever possible instead of Triggers and code
      Don’t want to allow users to save the order if a piece of information is missing? Validation Rules is a fast and easy-to-use alternative to writing custom Visualforce pages and controllers or Apex Triggers.
    • Use Approval Processes and Flows to implement logic and processes
      A lot of complex custom business logic and business processes can be defined using these two powerful tools. And probably the nicest benefit is that Approval Processes and Flows visualize the process, which makes it much easier to understand what’s going on than looking at lines and lines of Apex code.
    • Using Standard vs. Custom Objects
      We see this more often than one would think. Before creating a new custom object, check if there’s a standard object available that can address the functional requirements and/or can be customized to close the gap. Not only will this potentially save a lot of time, but also help control the number of custom objects in Salesforce, which is limited as we all know. A great example here is the Orders object that was released with Salesforce Spring ‘14. Before the Orders object was a Standard object, developers spent a lot of time and resources building functionality that is now available out-of-the-box. Keep in mind that there are three major Salesforce releases per year, so Salesforce is constantly adding new features and functionality. It’s always a good idea to check both the Salesforce1 Platform Release Notes and theForce.com Release Pages here on Salesforce Developers  for new standard objects and/or new features that may have required custom building in the past.
  7. Give an example of a standard object that’s also junction object.
  8. Describe a use case when you’d control permissions through each of the following:
    – Profiles
    – Roles
    – Permission Sets
    – Sharing Rules
  9. When should an org consider using Record Types?
  10. What are some use cases for using the Schema class?
  11. A trigger is running multiple times during a single save event in an org. How can this be prevented?
  12. Why is it necessary for most sales teams to use both Leads and Contacts?
  13. What is the System.assert method and when is it commonly used?
  14. What are the differences between SOQL and SOSL?
  15. Order the following events after a record is saved:
    – Validation rules are run
    – Workflows are executed
    – “Before” triggers are executed
    – “After” triggers are executed
  16. What is Trigger.old and when do you normally use it?
  17. When should you use a lookup instead of a master-detail relationship?
  18. What are the advantages of using Batch Apex instead of a trigger?
  19. What are the pros and cons when using a Workflow Rule Field Update vs. a Formula Field?
  20. What are the differences between a Map and a List?
  21. What are the advantages of using Batch Apex instead of a trigger?
  22. Describe a use case for Static Resources.
  23. Provide an example of when a Matrix report would be used. How about a Joined report?
  24. A group of users must be prevented from updating a custom field. What’s the most secure method of preventing this?
  25. When would you use the @future annotation?
  26. List three different tools that can be used when deploying code.
  27. When should an Extension be used instead of a Custom Controller?
  28. What are the advantages of using External Id fields?
  29. What are the uses of the <apex:actionFunction> tag?
  30. What are the differences between static and non-static variables in Apex?
  31. What are some best practices when writing test classes?
  32. What does the View State represent in a Visualforce page?
  33. What are three new features in the most recent Salesforce release?
  34. Describe the benefits of the “One Trigger per Object” design pattern.
  35. Write a SOQL query that counts the number of active Contacts for each Account in a set.
  36. Declaratively create logic in your org that prevents two Opportunities from being created on a single Account in a single day.
  37. Declaratively create logic in your org that prevents closed Opportunities from being updated by a non System Administrator profile.
  38. Can we create Trigger on Attachment ?
  39. How many Types of cloud in Salesforce.difference between Sales,Service and Custom Cloud?
  40. What is Web to Lead ?
  41. What is Case escalations rules ?
  42. What is Email Service and Email Template ?
  43. What is workflow ?
  44. What is profile ,Permission set and Role in Salesfroce ?
  45. What Is queue ?
  46. Difference Between Trigger.new & Trigger.old ?
  47. Difference between trigger.newMap and trigger.oldMap ?
  48. What is Sharing & without Sharing in apex Salesforce ?
  49. What is Collection in Salesforce ?
  50. How we populate value in Object using Trigger ?
  51. What is best Practice of Visualforce page and Apex Class ?
  52. Can we override profile permissions through Role ?
  53. Execution of life cycle of Apex Code ?
  54. Which Interface used in schedule class & Batch class ?
  55. Can we call a Normal Class in Schedule Class ?
  56. How we run Batch In Queue ?
  57. What is the Campaign & how its work ?
  58. How we convert the Lead & which fields are Optional ?
  59. Difference between Action Function & Remote Function ?
  60. How to implement many to many relationship in salesforce ?
  61. What is difference between many to many relationship & Lookup relationship ?
  62. What is Audit Trail ?
  63. What is field Set ?
  64. Difference between Custom setting and custom object ?
  65. How we make created by field to Writeable ?
  66. What is WhoID and WhatID in salesforce ?
  67. What is chatter and how we implement in salesforce ?
  68. What is communities and how many types of communities used in salesforce ?
  69. Difference between Rest Api and SOAP Api ?
  70. Governor limits in salesforce ?
  71. What is OWD in salesforce and what is Default OWD master Detail ?
  72. How many type of Report used in Salesforce ?
  73. What is Event and Task in salesforce ?
  74. How many types we can Deployed code in production ?
  75. How we enable History of any Object ?
  76. What is controller and standard controller and what is difference in both ?
  77. How we perform DML operation on page load ?
  78. What is Standard set Controller ?
  79. What is Data Migration ?
  80. How many line write in Apex class -10000
  81. What is Access specifier and what is Scope ?
  82. What is View State ? 
  83. How we remove Heap Size Issue ?
  84. Can we used more than one Controller in visualfroce page ?
  85. What is auto Response Role ? 
  86. What is Role hierarchy and where we can see this ?
  87. What is final and static keyword and where we used ?
  88. What is Apex variable and where we use of this ?
  89. How we show two object data in row and column ?
  90. What Is external ID ?
  91. What is import wizard.Limitations of this and difference between  data Loader & import wizard.
  92. What is Test class and how variable context used in apex Trigger ?
  93. What is group and how many type of group in salesforce ?
  94. What is connected App in salesforce ?
  95. What is meta data ?
  96. Can we deploy a class less than 75% of code coverage in production ?
  97. What is console and how we used.Can we override standard save functionality ?
  98. Can we call one future method to another future method ?
  99. Difference between SOQL and SOSL
  100. How to convert 15 digit to 18 digit ID in formula field in Salesforce ?
    CASESAFEID() is used to convert 15 digit ID to 18 digit ID in formula field in salesforce.

Common interview questions for Salesforce developers

Name three Governor Limits .                                                                                    Description Synchronous ...