Monday, 8 October 2018

SFDC scenario based interview Questions

1) Consider this scenario
I  have a profile  by name 'ProvideReadAccess' and two users U1 and U2 assigned to it. And I have object X.
My Question is I want to have ReadWrite access for U1 and ReadOnly access for U2  for the object X.
How do I do this?

Answer:
Read Access for both users is common hence in the Profile settings give 'Read' access for the object 'X'
By doing this User U2 will be able to read all the records( One condition satisfied) but U1 will also be able to only read the records(Second condition not satisfied).

So next what do we do is we create a permission set say 'GrantWriteAccess' and in this permission set we give the object 'X' the Write access and assign the user U1 to this permission set.(2nd condition satisfied).

Explanation about when and where to use permission set and profile


2) Consider a scenario
I have not given any CRUD permission in the profile 'P1' for an object O1, yet I'm able to create records for object 'O1'. How could this be possible?

Answer:  Any permission with respect to creation /deletion/Updating/viewing of object is possible only through permission set or Profile.
Meaning If we are able to create records in a object then the Create Permission in either Profile or in Permission Set should be enables. If its not enabled in the Profile then it has be in the Permission set.

So check for the permission set.

3)Consider a scenario

I have two un related objects Obj1 and Obj2. Now I want to create a Master Detail relation between these objects how do I do this?
One tow
Answer: First  choose which object has to be a Parent object(Master) and Child Object(Detail).
For our understanding lets say for now we decide Obj1 to be Master object and Obj2 to Detail object.

First lets under stand what's a Master Detail relation ? Every child should have  a parent. Which means every record in Obj2 should have a related parent record in Obj1. Also One child can have only one parent. But One parent can have multiple children.

Scenario 1: if there are pre existing records in the Obj2 then?
With the above understanding on Master Detail relation we have to be sure that every record in Obj2 has a related record in Obj1.
And in our scenario Obj1 and Obj2 are not related to each other. So first we have to create a basic Look up relation between these two objects so that we can establish a relation between these two objects.
So we follow below steps
 1st we create a Lookup field in the Child Object Obj2 pointing to Obj1 as parent.
2nd Update the Lookup field of all the records in Obj2 with a  value from the Obj1 (Related field)
3rd Then we convert the Look up field to Master Detail relation.


Scenario2: If there are no pre existing records in the Obj2 then?


4)Consider a scenario
I'm trying to implement Pagination. Initially i want to dispaly 50 records and when user click on Next button, the records stating from 51 to 100 should get displayed. How do I accomplish this.

Answer: The key question here is how do we fetch next 50 records when user clicks on 'Next'?
                   One possible way to implement this is to have 'OFFSet' used in SOQL which fetches the records.
                   Eg:   SELECT Name from Merchandise__c 
                            where Price__c > 5
                            Order by Name Limit  100
                             OFFSET 50

5) I have 2 workflow Rules and two Fields F1 and F2
When ever F1 is updated to value= 10,  WF1 fires and updates F1 value to 20 and F2  value to 30
When ever F1 values=  20 there is another Workflow W2 fires which will update F1 to 10 and F2 to 20
What will be the outcome of this Workflow rule.


Answer: This scenario will cause  recursive Workflow rule
                   This will exhaust the governor limit and result in error

6)I have a User, Who will leave the organization tomorrow. He is basically a manager and there are 15 users below him.
Now when this user leaves the organization i would generally inactivate the User.
But now my concern is if I inactivate this user What happens to the Role hierarchy? the assignment rules, Approval processes, the records created by him and records to which he is the default owner like leads and cases. And what would be best possible solution to keep this application intact and running and yet have this user de activated?

Answer: To prevent users from logging into your organization while you perform the steps to deactivate them, you can freeze user accounts. [Spring Summer 14]
So in this way untill you find ways to remove this User from Role hierarchy/assigenment rules/update the Owner of the records created by him / from any place where this user is used, we can make use of FREEZE button on the USer record.
Note:
1. When we click on FREEZE button, the user will not be able to login  to the application any more.
2. Freezing user accounts doesn't frees the user licenses available for use in your organization. We have to      de activate the user to free the license.

7) I want to delete 20000 records and I dont want them to be recovered from recycle bin.
OR
I want to do a mass delete on set of records and dont what them getting into recycle bin.
What possible options do I have?

- Yes this is possible, Use Hard Delete Option

8)Let say I have a page which displays the set of records from Account object and I'm using a standard controller.  Now I have two users belonging to same Profile. When they login and view this page, they get  a message "Insufficient privileges". What could be the reason for this? Or who would u arrive at a solution?
- Notice below points:
- Question speaks about standard Object and Standard Controller.
 - Also remember permission to a object is given by Profile.
So we need to check if the user has pemssion to read data of this Object.
Only if the permission is given to the user,he'll be able at access them else he will get an error message as "Insufficient privileges"


9)I have Stadard Controller and Controller Extension. You can write all that logic in Controller Extension which can be written in Custom Controller. Also both Controller Extenstion and Custom controller execute in System Mode. So Why do we need Custom Controller ?

Answer:
 1st point Controller Extension cant exist on its own. It has to be implemented on a Standard Controller or a custom controller.
So keeping the above point in mind, Lets say certain methods needs to be executed in User Mode and certain in System Mode. In this scenario it makes absolute sense to User Standard Controller with Custom Extenstion. Where in using  Standard Controller provides all pre existing features of Force.com platform.
But note that When we use Standard Controller All the Sharing rules, permissions of a user are respected.
So if this what we wanted then we should go for an implementaiton of this sort.

Other wise if we are building all features on own like Save Edit Update and delete then we should be using Custom Controller.

10) Let say I have a page which displays the set of records from Account obkect and i'm using a standard controller. Now I have two users belonging to same profile. When they login and view this page, they get a message "Insufficient privileges" . What could be the reason for this? Or who would u arrive at a solution?

-Notice below points:

==> Quetion speak about standard Object and Standard Controller.
==> Also remeber permission to a object is given by profile.
So we need to check if the user has permission to read of this Object.
Only of the permission is given to the user, he'll be able at access them else he will gwt an error messages as "Insufficient privileges".

Some Realtime Interview Quetions



     
1) Salesforce provides two WSDL files, what are the differences?

Resolution:
     
Salesforce provides a WSDL (Web Service Description Language) files. They are called "Enterprise WSDL" and "Partner WSDL". A WSDL is an XML-document which contains a standardized description on how to communicate using a web service (the Salesforce API is exposed as a web service). The WSDL is used by developers to aid in the creation of Salesforce integration pieces. A typical process involves using the Development Environment (eg, Eclipse for Java, or Visual Studio for .Net) to consume the WSDL, and generate classes which are then referenced in the integration.

The primary differences between the two WSDL that we provide are:

Enterprise WSDL:
a) The Enterprise WSDL is strongly typed.
b) The Enterprise WSDL is tied (bound) to a specific configuration of Salesforce (ie. a specific organization's Salesforce configuration).
c) The Enterprise WSDL changes if modifications (e.g custom fields or custom objects) are made to an organization's Salesforce configuration.

For the reasons outlined above, the Enterprise WSDL is intended primarily for Customers.

Partner WSDL:
a) The Partner WSDL is loosely typed.
b) The Partner WSDL can be used to reflect against/interrogate any configuration of Salesforce (ie. any organization's Salesforce configuration).
c) The Partner WSDL is static, and hence does not change if modifications are made to an organization's Salesforce configuration.

For the reasons outlined above, the Partner WSDL is intended primarily for Partners.

To download a WSDL file when logged into Salesforce:

1. Click Setup | Develop | API

2. Click the link to download the appropriate WSDL. It will be something like: "Generate <type_of_wsdl> WSDL"

3. Save the file locally, giving the file a ".wsdl" extension.



 

2) I have created a batch process. Let say I have thousands of records to process. Now what i want is when there is an error

encounter or some problem found in the data during the batch process, I want to stop or abort the batch process. Is it possible ?

ANS: public void execute(Database.BatchableContext bc, List<SObject> scope) {
   
      try {
       
            ...
   
            }
      catch (Exception e) {
      
             // Report errors here
      
             System.abortJob(bc.getJobId());
   
            }
}


3) If Run a Batch classe some records would be failed Now how to recover that failed records.?

 
using below method we can.
Database.SaveResult[] SaveResultList = Database.insert(accts,false); 

4) Schedule apex to run every 10 Min..??

You have to schedule your batch for 6 times, if you want to run batch for every 10 mints.
System.schedule('Scheduled Job 1', '0 0 * * * ?', new scheduledTest());

System.schedule('Scheduled Job 2', '0 10 * * * ?', new scheduledTest());
 
System.schedule('Scheduled Job 3', '0 20 * * * ?', new scheduledTest());
 
System.schedule('Scheduled Job 4', '0 30 * * * ?', new scheduledTest());

System.schedule('Scheduled Job 5', '0 40 * * * ?', new scheduledTest());
 
System.schedule('Scheduled Job 6', '0 50 * * * ?', new scheduledTest());



 

5) The difference between regular (non-static) and static methods


Java is a Object Oriented Programming(OOP) language, which means we need objects to access methods and variables inside of a class. However this is not always true.
While discussing static keyword in java, we learned that static members are class level and can be accessed directly without any instance.
In this article we will see the difference between static and non-static methods.

Static Method Example
class StaticDemo
{
  
public static void copyArg(String str1, String str2)
   {
       //copies argument 2 to arg1
       str2 = str1;
       System.out.println("First String arg is: "+str1);
       System.out.println("cond String arg is: "+str2);
   }
  
public static void main(String agrs[])
   {
      /* This statement can also be written like this:
       * StaticDemo.copyArg("XYZ", "ABC");
       */
     
copyArg("XYZ", "ABC");
  
}
}
 
Output:

First String arg is: XYZ
Second String arg is: XYZ
As you can see in the above example that for calling static method, I didn’t use any object. It can be accessed directly or by using class name as mentioned in the comments.

Non-static method example
class JavaExample
{
   public void display()
   {
       System.out.println("non-static method");
   }
   public static void main(String agrs[])
   {
         JavaExample obj=new JavaExample();
         /* If you try to access it directly like this:
          * display() then you will get compilation error
          */
       obj.display();
   }
}
Output:

non-static method
A non-static method is always accessed using the object of class as shown in the above example.

Notes:
How to call static methods: direct or using class name:

StaticDemo.copyArg(s1, s2);
OR copyArg(s1, s2);
How to call a non-static method: using object of the class:

JavaExample obj = new JavaExample();
Important Points:

Static Methods can access static variables without any objects, however non-static methods and non-static variables can only be accessed using objects.
Static methods can be accessed directly in static and non-static methods. For example the static public static void main() method can access the other static methods directly. Also a non-static regular method can access static methods directly.


6) Best Practices for Improving Visualforce Performance

>> Cache any data that is frequently accessed, such as icon graphics.

>> Avoid SOQL queries in your Apex controller getter methods.

>> Reduce the number of records displayed on a page

>> “Lazy load” Apex objects to reduce request times.

>> Consider moving any JavaScript outside of the <apex:includeScript> tag and placing it in a <script> tag



28. What are the Best Practises for Improving Visualforce Performance ?
Answer:
1) The view state size of your Visualforce pages must be under 135 KB. By reducing your view state size, your pages can load quicker and stall less often.
2) Large page sizes directly affects load times. To improve Visualforce page load times:
· Cache any data that is frequently accessed, such as icon graphics.
· Avoid SOQL queries in your Apex controller getter methods.
· Reduce the number of records displayed on a page by adding filter condition in SOQL
3) Reduce Multiple Concurrent Requests: use <apex:actionpoller>

4) By using the with sharing keyword when creating your Apex controllers, you have the possibility of improving your SOQL queries by only viewing a data set for a single user.


see More: https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_best_practices_performance.htm


7)I need to ascending order of following strings based on first name manu yadav, ann reddy, paa goud how can you achive this.

list<string> str = new list<string>();
 
str.add('manu yadav');
str.add('ann reddy');
str.add('paa goud');
 
str.sort();
 
system.debug('the list of names'+str);


 

8) Below is the Salesforce Order of Execution:


System Validation rule (required field, field format) (SV)
 
Before Triggers are executed (BT)
 
Custom Validation rules are checked (CV)

After Triggers are executed (AT)

Assignment Rules are executed (AR)

Auto-Response Rules are executed (ARR)

Workflow Rules are executed (WR)
 
Before and after triggers are executed one more time if the workflow rule updates a field (BT & AT)
 
Escalation Rules are executed (ER)
 
Parent Rollup Summary Formula or Cross Object Formula fields are updated in the respective objects. (RSF, COF)

(These parent records also goes through the entire execution order)

Criteria Based Sharing rules are evaluated (CBS)

Any Post-Commit Logic is executed (PCL) 
(like sending an email)

Below will help you to remember Order of Execution in Salesforce:

SV -> BT -> CV -> AT -> AR -> ARR -> WR (BT, AT) -> ER -> RSF, COF -> CBS -> PCL