Concepts or coding lessons of Salesforce that you can implement easily

Salesforce Interview Questions - Part 3

51. What is the difference between apex:dataTable and apex:pageBlockTable components in Visualforce?
Answer : Both component is used to render data in tabular format. apex:dataTable will render records in simple HTML table format whereas the apex:pageBlockTable possess default look and feel of salesforce standard CSS and must be written inside apex:pageBlock component.

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

53. How can you lock record using SOQL so that it cannot be modified by other user.
Answer : We will need FOR UPDATE clause of SOQL.
Example :
SELECT Id FROM Contact LIMIT 2 FOR UPDATE

54. In trigger, lets say you have system.debug() statement after adderror() method. Will system.debug() be statement executed in Trigger after adderror() method?
Answer: adderror() method is not error statement rather its normal execution flow and all the statements written after adderror() will be executed normally.

55. How to get total number of Child records in Lookup relationship?
Answer: As Rollup Summary field is only supported in Master detail, we cannot use it for Lookup. 
There are following two ways.

1. Inline Visualforce page
2. Trigger on Child Object, which will update field in Parent record if child record is inserted, deleted or undeleted.
If anyone has any other idea please comment. I will add that too.

56. What will happen if you try to update record in After Trigger Context?
Answer : You will get an error saying record is Read only.

How to get IP Address of User in Apex?
Answer : String ipAddress = ApexPages.currentPage().getHeaders().get('X-Salesforce-SIP');

X-Salesforce-SIP has the value if there is no caching integration (sandbox, developer edition orgs) or via the secure URL.

57. We have a Time Based Workflow and there is Action scheduled to be executed. If we Deactivate the workflow, Scheduled actions will be removed from queue or not?
Answer : Even after deactivation of workflow, its action will be active in queue.

58. How to clear the Time based workflow action queue ?
Answer : Two ways to achieve this. 
  • Make criteria false for all those records. 
  • Go to Set up -> Monitoring -> Time Based Workflow and search for scheduled actions and then remove from queue.
59. We have Time Based Workflow and there is action scheduled to be executed. Can we delete that workflow?

Answer : If a workflow have any pending time dependent action, then we cannot delete the workflow.

60. While creating workflow on Task object, what difference observed on available actions?
Answer : Send Email action is not available while creating workflow on task object.

61. Explain few considerations for @Future annotation in Apex.
Answer 
Remember that any method using the future annotation requires special consideration because the method does not necessarily execute in the same order it is called.
  • Methods with the future annotation cannot be used in Visualforce controllers in either getMethodName or setMethodName methods, nor in the constructor.
  • You cannot call a method annotated with future from a method that also has the future annotation. Nor can you call a trigger from an annotated method that calls another annotated method.
  • Method must be static
  • Cannot return anything i.e. ( Only Void )
  • Parameter to @future method can only be primitive or collection of primitive data type.
  • To test @future methods, you should use startTest and stopTest to make it synchronous inside Test class.
62. How you can use Datetime field as a criteria in SOQL Query ?
Answer 
We cannot use Datetime as condition in Where Clause in between single Quotes.
You can do something like this ,
WHERE CreatedDate > 2017-01-02T00:00:00Z
OR you can also use Date Literals like
WHERE CreatedDate > YESTERDAY

63. Why I am not able to find list of Person Account fields in Field Level Security (FLS) settings when navigated to fields on Account Object.
Answer :

Field Level Security (FLS) of Person Account fields are controlled by Contact Fields. So, if you want to setup FLS of Person Account Fields navigate to fields of Contact and it will be reflected on Person Account.

64. Explain functionality of Force.com Query Optimizer.
Answer :
The Force.com query optimizer:

  • Determines the best index from which to drive the query, if possible, based on filters in the query
  • Determines the best table to drive the query from if no good index is available
  • Determines how to order the remaining tables to minimize cost
  • Injects custom foreign key value tables as needed to create efficient join paths
  • Influences the execution plan for the remaining joins, including sharing joins, to minimize database input/output (I/O)
  • Updates statistics

65.How to report on User License field?
Answer :
Create formula field in User Object with formula Profile.UserLicense.Name.
Note: You need to copy and paste this value because it doesn’t show up in the fields drop down.

66. Explain Skinny table in Salesforce.
Answer :
Salesforce creates skinny tables to contain frequently used fields and to avoid joins, and it keeps the skinny tables in sync with their source tables when the source tables are modified. To enable skinny tables, contact Salesforce.com Customer Support.
For each object table, Salesforce maintains other, separate tables at the database level for standard and custom fields. This separation ordinarily necessitates a join when a query contains both kinds of fields. A skinny table contains both kinds of fields and does not include soft-deleted records.

67. What are the considerations for Skinny Table?
Answer :

  • Skinny tables can contain a maximum of 100 columns.
  • Skinny tables cannot contain fields from other objects.
  • Skinny tables are not copied to sandbox organizations. To have production skinny tables activated in a sandbox organization, contact Salesforce.com Customer Support.

68. How to capture errors after using Database DML methods in Salesforce?
Answer :
List<Contact> lstContact = new List<Contact>();
Contact con = new Contact (lastName = 'Talekar', SQL_Server_Id__c='3',firstName='Nitish');
lstContact.add(con);
// add some other contacts records in contact List
Database.UpsertResult[] results = Database.upsert( lstContact, Contact.SQL_Server_Id__c.getDescribe().getSObjectField() ,false ) ;

for(Integer i=0;i<results.size();i++){
    if (!results.get(i).isSuccess()){
        Database.Error err = results.get(i).getErrors().get(0);
        System.debug('Error - '+err.getMessage() + '\nStatus Code : '+err.getStatusCode()+'\n Fields : '+err.getFields());
    }
}

69. Which fields are automatically Indexed in Salesforce ?
Answer :

  • RecordTypeId
  • Division
  • CreatedDate
  • Systemmodstamp (LastModifiedDate)
  • Name
  • Email (for contacts and leads)
  • Foreign key relationships (lookups and master-detail)
  • The unique Salesforce record ID, which is the primary key for each object.

70. Which fields cannot be added as a custom Index?
Answer :

  • multi-select picklist
  • text area (long)
  • text area (rich)
  • non-deterministic formula fields (Like any formula field using function NOW() or Today() )
  • encrypted text fields.

71. What is best practice to refer dynamic custom messages in Visualforce with multi-language support ?
Answer :
Using Custom Label or OutputField or InputField tag, Platform itself will take care of internationalization. However in some cases, Message needs to be dynamic at the same time it should also support muti-language. In Custom Label, we cannot save dynamic String.

Let’s assume we want to show message something like “DEVELOPERNAME is not authorized to access this page”.
Here, Developername should be dynamically changed in visualforce which supports multilanguage. For each developername, it is not feasible to create custom labels. So below workaround can be used :

Step 1 : Create a Custom Label with text  {0} is not authorized to access this page. In every language, dynamic value should represented by {0}.

Step 2 : In Controller of Visualforce write something like this :

String developerName = 'Some Developer Name';
String message = String.format(Label.DEVELOPERNAME , new String[] { developerName });


72. What are the tools included in lightning ?
Answer :

Lightning Component Framework – Components and extensions that allow you to build reusable components, customise the Salesforce1 Mobile App, and build standalone apps.
Lightning App Builder – A new UI tool that lets you build apps lightning fast, using components provided by Salesforce and platform developers.
Lightning Connect – An integration tool that makes it easier for your Force.com app to consume data from any external source that conforms to the OData spec.
Lightning Process Builder – A UI tool for visualizing and creating automated business processes.
Lightning Schema Builder – A UI tool for viewing and creating objects, fields, and relationships.

73. Difference between Chatter API and Connect API in Salesforce.
Answer :

Chatter API is REST API for Chatter to display Salesforce data, especially in mobile applications. Responses are localized, structured for presentation, and can be filtered to contain only what the app needs.
Connect API provides apex classes for accessing the same data available in Chatter REST API. Use Chatter in Apex to create custom Chatter experiences in Salesforce.

74. What the Concurrent Request Limit is and Why it Exists in Salesforce?
Answer :
The multi tenant Force.com platform uses governor limits to ensure that system resources are available to all customers and to prevent any one customer from monopolizing them. If a governor limit is exceeded, the associated execution governor limit issues a runtime exception that cannot be handled. When you design your applications, you can help plan for their growth by keeping these limits in mind.

One of the limits customers frequently reach is the concurrent request limit. Once a synchronous Apex request runs longer than 5 seconds, it begins counting against this limit. Each organisation is allowed 10 concurrent long-running requests. If the limit is reached, any new synchronous Apex request results in a runtime exception. This behavior occurs until the organization’s requests are below the limit.

Ultimately, this limit is in place to protect the user experience. Once the limit is reached, new synchronous Apex requests are denied. This behaviour can be disruptive to your work.

Some useful tips:
  • Convert synchronous processes to asynchronous processes. Batch Apex might be a viable alternative. Limit synchronous Web service callout.
  • Use the Streaming API instead of polling
  • Tune SOQL and DML operations. Make sure that your queries are selective. Limit the number of records in your list views. Avoid data skew.
75: What is custom metadata type ?
Answer : Custom metadata is customizable, deployable, packageable, and upgradeable application metadata. First, you create a custom metadata type, which defines the form of the application metadata. Then you build reusable functionality that determines the behavior based on metadata of that type. Similar to a custom object or custom setting, a custom metadata type has a list of custom fields that represent aspects of the metadata.
Before Custom metadata type, we were using Custom settings of List type. Problem with custom setting was that, during migration or in packages, data were not migrated. We had to either use data loader or some API to create initial data. However, if we package custom metadata type or migrate it, data will also be migrated along with it.

76: Which component in Salesforce ends with __mdt and __s ?
Answer : Custom metadata types ends with __mdt (meta data type), just like custom object or custom fields ends with __c.

When we create Geolocation field in Salesforce, lets say by name location__c then internally Salesforce creates subfields with extension __s
In this case location_latitude__s and location_longitude__s.

77: Which interface needs to be implemented in Apex to be used in Flow ?
Answer : We can execute apex as well using flow by annotating it with @InvocableMethod and marking method as static. However this method only takes one parameter of type list. If we want to send multiple parameters, then simplest way is to create comma separated list of argument and pass it. In this method, we can break it and use according. 
Below is sample code

Global class Flow_UpdateContactField {    
    @InvocableMethod
    public static void performUpdate(List<String> lstCSV){
        List<String> recIds = lstCSV[0].split(',');
        // 0 - ContactId, 1-field1__c
Contact objCon = new Contact(Id=recIds[0], field1__c=recIds[1]);
update objCon;        
    } 

}

78: How to get the list of all available sobject in salesforce database using Apex (Dynamic Apex) ?
Answer :
Map<String, Schema.SObjectType> m =  Schema.getGlobalDescribe();

79. How to display error messages in the visualforce page ?
Answer :
In Apex use below code to create the error message for visualforce.
Apexpages.addMessage( new ApexPages.Message (ApexPages.Severity.ERROR, 'Required fields are missing. '));
And in Visualforce page,  add below tag where you want to display the error message which display the error message.

<apex:pageMessages > </apex:pageMessages>

80: How to read the parameter value from the URL in Apex?
Answer :
Consider that the parameter name is AccountName then use below code snippet:

String objAccountName = Apexpages.currentPage().getParameters().get('AccountName');

More Salesforce Interview Questions and Answers:

loading...

No comments:

Post a Comment