Thursday 7 December 2017

SFDC Interview Questions - Part 4

27.  What is difference between WhoId and WhatId in the Data Model of Task ?
Ans :
WhoID refers to people things. So that would be typically a Lead ID or a Contact ID
WhatID refers to object type things. That would typically be an Account ID or an Opportunity ID

28. Where is the option of the report for the “Custom Object with related object” and what are the condition to generate related reports?
Ans :
If the parent object is the standard object provided by the salesforce like “Account”, “Contact” then the report will be in there section with related custom object.
If both objects are the custom then the report will be in “Other Reports” Sections.
Following are the conditions to get the report of related objects:
·                     On both the objects, Reports option must be enable.
·                     The relationship between both of them must be “Master – detail relationship”.

29. How you can provide the User Login (Authentication) in Public sites created by Salesforce.
Answer : We can provide the authentication on public sites using “Customer Portal”.

This part of the interview question mainly focus on the dynamic Apex feature of thesalesforce.com .
30 : What is the dynamic Apex?
Ans :

Dynamic Apex enables developers to create more flexible applications by providing them with the ability to “Access sObject and field describe information”, “Write Dynamic SOQL Queries”, “Write Dynamic SOSL Queries” and “Dynamic DML”.

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

32 : How to create instance of sobject dynamically? Normally the sobject is created like “Account a = new Account();”. But if you are in situation that you don’t know which sobject is going to be instantiated ? Means it will be decided at runtime, how you will handle it? Hint : Use Dynamic Apex.
Ans:
1
public SObject getNewSobject(String t)
2
{

3
4
    // Call global describe to get the map of string to token.

5
    Map<String, Schema.SObjectType> gd = Schema.getGlobalDescribe();
6

7
    // Get the token for the sobject based on the type.
8
    Schema.SObjectType st = gd.get(t);

9

10
    // Instantiate the sobject from the token.

11
    Sobject s = st.newSobject();
12

13
    return s;
14
}

33 : How to get all the fields of sObject using dynamic Apex?
Ans:
1
Map<String, Schema.SObjectType> m  = Schema.getGlobalDescribe() ;
2
Schema.SObjectType s = m.get('API_Name_Of_SObject') ;

3
Schema.DescribeSObjectResult r = s.getDescribe() ;
4
Map<String,Schema.SObjectField> fields = r.fields.getMap() ;

34 : How to get all the required fields of sObject dynamically?
Ans:

There is no direct property available in Apex dynamic API to represent the required field. However there is another way to know about it.
If any field have below three properties then it is mandatory field.
1.                  If it is Creatable
2.                  If it is not nillable and
3.                  If it does not have any default value
1
Map<String, Schema.SObjectType> m  = Schema.getGlobalDescribe() ;
2
Schema.SObjectType s = m.get(so.apiName) ;

3
Schema.DescribeSObjectResult r = s.getDescribe() ;
4
Map<String,Schema.SObjectField> fields = r.fields.getMap() ;

5
6
for(String f : fields.keyset())

7
{
8
    Schema.DescribeFieldResult desribeResult = fields.get(f).getDescribe();

9
    if( desribeResult.isCreateable()  && !desribeResult.isNillable() && !desribeResult.isDefaultedOnCreate() )
10
    {

11
//This is mandatory / required field
12
    }

13
}

35 : How to display error messages in the visualforce page ?
Ans:
In Apex use below code to create the error message for visualforce.
1
Apexpages.addMessage( new ApexPages.Message (ApexPages.Severity.ERROR, 'Required fields are missing. '));
in Visualforce page add below tag where you want to display the error message.
<apex:pageMessages ></apex:pageMessages>

36 : What is property in Apex? Explain with advantages.
Ans: 

Apex mainly consist of the syntax from the well known programming language Java. As a practice of encapsulation in java we declare any variable as private and then creates the setters and getters for that variable.
1
private String name;
2
public void setName(String n)

3
{
4
  name = n;

5
}
6
public String getName()

7
{
8
 return name;

9
}
However, the Apex introduced the new concept of property from language C# as shown below:
1
public String name {get; set;}
As we can see how simple the code is and instead of using nearly 8 to 11 lines all done in 1 line only. It will be very useful when lots of member is declared in Apex class. It has another advantage in “number of lines of code” limit by salesforce which will drastically reduced.

37 : What is the controller extension ?
Ans:

Any apex class having a public constructor with Custom Controller or Standard Controller object as a single argument is known as controller extension.

38 : Explain the need or importance of the controller extension.
Ans:

Controller extension is very useful and important concept introduced by the salesforce recently. It gives the power to programmer to extend the functionality of existing custom controller or standard controller.
A Visualforce can have a single Custom controller or standard controller but many controller extensions.
we can say that the custom extension is the supporter of custom or standard controller.
Consider one example : If there is one controller written and used by the multiple visualforce pages and one of them needs some extra logic. Then instead of writing that logic to controller class (Which is used by many visualforce pages) we can create a controller extension and apply to that page only.

39 : How to read the parameter value from the URL in Apex?
Ans:

Consider that the parameter name is “RecordType”.
1
String recordType = Apexpages.currentPage().getParameters().get('RecordType');
40. What is Master Detail relationship and look up relationship in Salesforce?
Ans:
Master Detail relationship is the Parent child relationship. In which Master represents Parent and detail represents Child. If Parent is deleted then Child also gets deleted. Rollup summary fields can only be created on Master records which will calculate the SUM, AVG, MIN of the Child records.
Look up relationship is something like “has-a” (Containership) relationship. Where one record has reference to other records. When one record is deleted then there is no impact on other records.

41. Can we convert the lookup relationship to Master Detail relationship?
Ans:
We can convert the lookup relationship to master detail relationship if and only if all the existing record has valid lookup field.

42. In How many way we can invoke the Apex class?
Ans:
1.                  Visualforce page
2.                  Trigger
3.                  Web Services
4.                  Email Services

43. Can we create Master Detail relationship on existing records?
Ans:
No. As discussed above, first we have to create the lookup relationship then populate the value on all existing record and then convert it.

44. How validation rules executed? is it page layout / Visualforce dependent?
Ans :
The validation rules run at the data model level, so they are not affected by the UI. Any record that is saved in Salesforce will run through the validation rules.

45. What is the difference between database.insert and insert ?
Ans:
insert is the DML statement which is same as database.insert. However, database.insert gives more flexibility like rollback, default assignment rules etc. we can achieve the database.insert behavior in insert by using the method setOptions(Database.DMLOptions)
Important Difference:
·                     If we use the DML statement (insert), then in bulk operation if error occurs, the execution will stop and Apex code throws an error which can be handled in try catch block.
·                     If DML database methods (Database.insert) used, then if error occurs the remaining records will be inserted / updated means partial DML operation will be done.

46. What is the scope of static variable ?
Ans:
When you declare a method or variable as static, it’s initialized only once when a class is loaded. Static variables aren’t transmitted as part of the view state for a Visualforce page.
Static variables are only static within the scope of the request. They are not static across the server, or across the entire organization.

47. Other than SOQL and SOSL what is other way to get custom settings?
Ans:
Other than SOQL or SOSL, Custom seting have there own set of methods to access the record.
For example : if there is custom setting of name ISO_Country,
1
SO_Country__c code = ISO_Country__c.getInstance(‘INDIA’);
2
//To return a map of data sets defined for the custom object (all records in the custom object), //you would use:

3
Map<String,ISO_Country__c> mapCodes = ISO_Country__c.getAll();
4
// display the ISO code for India

5
System.debug(‘ISO Code: ‘+mapCodes.get(‘INDIA’).ISO_Code__c);
6
//Alternatively you can return the map as a list:

7
List<String> listCodes = ISO_Country__c.getAll().values();

48. What happen if child have two master records and one is deleted?
Ans :
Child record will be deleted.

49. What is Difference in render, rerender and renderas attributes of visualforce?
Ans:
render – It works like “display” property of CSS. Used to show or hide element.
rerender – After Ajax which component should be refreshed – available on commandlink, commandbutton, actionsupport etc.
renderas – render page as pdf, doc and excel.

50. What is Scheduler class in Apex?
Ans:
The Apex class which is programed to run at pre defined interval.
Class must implement schedulable interface and it contains method named execute().
There are two ways to invoke schedular :
1.                  Using UI
2.                  Using System.schedule
The class which implements interface schedulable get the button texted with “Schedule”, when user clicks on that button, new interface opens to schedule the classes which implements that interface.
To see what happened to scheduled job, go to “Monitoring | Scheduled jobs “
Example of scheduling :
1
scheduledMerge m = new scheduledMerge();
2
String sch = '20 30 8 10 2 ?';

3
system.schedule('Merge Job', sch, m);
To see how to make crone job string – refer this URL.

51. Explain Permission sets released in Winter 12.
Ans :
A permission set is a collection of settings and permissions that give users access to various tools and functions. The settings and permissions in permission sets are also found in profiles, but permission sets extend users’ functional access without changing their profiles. For example, to give users access to a custom object, create a permission set, enable the required permissions for the object, and assign the permission set to the users. You never have to change profiles, or create a profile for a single use case. While users can have only one profile, they can have multiple permission sets.

52. What is the difference between External ID and Unique ID?
Ans:
External ID

This is a field that usually references an ID from another (external) system. For instance, if the customer has an Oracle Financials system that they will be linking with salesforce.com, it may be easier for them to be able to refer to the Oracle ID of account records from within salesforce. So they would create an external ID in salesforce.com and they would load the Oracle ID into that field for each account. They can then refer to that ID field, rather than thesalesforce.com id.
Additionally, if you have an external ID field, the field becomes searchable in the sidebar search. You also can use the upsert API call with the extenal ID to refer to records.
You can have multiple records with the same external ID (though it is not reccomended, as it will defeat the purpose of the external id) .
External Id available for Text, Number and Email field types.
External Id is used in upsert operations.
·                     If external id is absenor not matched then insert happens.
·                     If external id matched once then record will be updated.
·                     If external id is matched multiple times then error occurs.
Unique ID field
This is a setting for the field that will prevent you from using the same value in multiple records for the unique field. So if I create a 5 character text field and make it unique, and I create a record with the value “12345″ i will not be able to create another record with that same value in the unique field. If i try to do so, I will get an error saying that the value is already in use.
Often, External Ids are set with the unique property so that the IDs will be unique to each record.
Salesforce – External Id option while creating field

53. How to get the picklist value in Apex class?
Ans :
Using Dynamic apex, we can achieve this.on object of type pickilist, call getDescribe(). then call the getPicklistValues() method. iterate over result and create a list. bind it to <apex:selectOptions>.

54. What are the types of controller in visual force?
Ans :

There are basically two types of Controller in Visual force page.
1.                  Standard Controller and
2.                  Custom Controller

55. How many Controllers can be used on single VF page?
Ans :
Only one controller can be used salesforce. Other than them, Controller extension can be used. There may be more than one Controller extention.
Example :
1
<apex:page standardController="Account"
2
extensions="ExtOne,ExtTwo" showHeader="false">

3
<apex:outputText value="{!foo}" />
4
</apex:page>
if ExtOne and ExtTwo, both have the method getFoo() then the method of ExtOne will be executed.
A controller extension is any Apex class that contains a constructor that takes a single argument of type ApexPages.StandardController or CustomControllerName, where CustomControllerName is the name of a custom controller that you want to extend.

56. Explain System.runAs()
Ans : 

Generally, all Apex code runs in system mode, and the permissions and record sharing of the current user are not taken into account. The system method, System.runAs(), lets you write test methods that change user contexts to either an existing user or a new user. All of that user’s record sharing is then enforced. You can only use runAs in a test method. The original system context is started again after all runAs() test methods complete.
Example :
1
System.runAs(u) {
2
// The following code runs as user 'u'

3
System.debug('Current User: ' + UserInfo.getUserName());
4
System.debug('Current Profile: ' + UserInfo.getProfileId()); }

5
// Run some code that checks record sharing
6
}

57. Explain Test.setPage().
Ans:

It is used to set the context to current page, normally used for testing the visual force controller.

58. What is the custom settings ?
Ans : 

Custom settings are similar to custom objects and enable application developers to create custom sets of data, as well as create and associate custom data for an organization, profile, or specific user. All custom settings data is exposed in the application cache, which enables efficient access without the cost of repeated queries to the database. This data can then be used by formula fields, validation rules, Apex, and the Web services API.


No comments:

Post a Comment

Batch Apex

1. What are transaction limits in apex? Total number of SOQL queries issued1 - 100 Total number of records retrieved by SOQL queries - 50...