anusha(salesforce developer)

imp Q&A For interview

Q: What is the data type of Trigger.New?
- Trigger.New is of Data Type List (A collection of records).

Q: What is the difference between Trigger.New and Trigger.Map?
- Trigger.New returns a ordered list of records but Trigger.Map returns a map(Key value pair).

Q: What is the difference between User Context and System Context? /What is the difference between running in user Mode or system Mode?
- In User Context/Mode the execution of class/method takes place considering the logged in users  
       Permission (Sharing rules, OWD, field level security...)
  In System Context/Mode none of the permissions associated with the logged in user is considered.
       The execution takes place as though the user has full fledged rights on everything.

Q: Explain the key words With Sharing and Without Sharing.
- Consider  a Custom Object  'MarksDetail' has OWD security set to 'Private',
   Now lets say  we have  2 classes 'TestResult' and 'ExamResult'
   Follow the below scenarios to arrive the solution

  // Declaring the Class 'TestResult' with a method 'returnTestResult'
public with Sharing Class TestResult
{
      public void retunTestResult()
      {
        // Query to return a set of data
        [select id from customobject];
      }
}

Lets consider customObject has OWD as private
ThenThe output of this query will be the records created by the logged in user.

// Declaring the Class 'ExamResult' with a method 'returnExamResult'
public without Sharing Class ExamResult
{
      public void returnExamResult()
      {
// Query to return a set of data
        [select id from customobject];
      }
    TestResult obj = new TestResult();
    obj.retunTestResult();
}
Lets consider customObject has OWD as private

ThenThe output of this query will be all the records in the custom objects.
Hence, Without sharing will not respect the sharing rules/owd/manualsharingetc..

Q: Why go for Dynamic SOQL quires?
 - Lets say we are inserting 100 records, all the 99 records will get inserted without any error but 1 records       fails.
   Then in normal SQOl query inserting, the entire transaction will fail and no records will be inserted
   But when we go for Dynamic SOQL quiry, with the above scenario we can insert all 99 records and gather the error log of that 1 records.
 - Also Salesforce SOQL does not allow Select * from Account query (Which would get all the fields from a object)
   In order to implement this we can Salesforce 'Schema Describe' object to dynamicall build SOQL queries at run time to query for all fields on a record.
 
-System is Class, Name few methods in it
5 System Methods.
   assert [Ex: System.assert]
   assertequals [Ex: System.assertequals]
   assertNotEqual [Ex: System.assertNotEqual]
   debug [Ex: System.debug]
   currentPageReference [Ex: System.currentPageReference]
   now [Ex: System.now]
   runas    [Ex: System.runas]
   Today [Ex: System.Today]

 
 
-Test is Class, Name few test methods in it
The following are methods for Test Class. All methods are static.
5 Test Methods
startTest [Ex: Test.startTest]
stoptest [Ex: Test.stoptest]
isrunningtest()
setCurrentPage

-UserInfo is Class, Name few methods in it
-Contains methods for obtaining information about the context user.
5 UserInfo methods
-getProfileID()
-getUserId()
-getFirstName
-getLAstName
-getName
-getsessionId()
-getUserRoleId()
-getUserType()

-String is a class, and name few methods in it
5 methods of String Class
- Contains
-equals
-endswith
-indexof
-isblank
-isnumeric
-substring
-compareTo

-Set is class, Name the methods in it
add
addall
size
contains

-Map is class, Name the methods in it
get
keyset
containskey
size
values
put

-sObject is Class,few methods in this class are
sObject methods are all instance methods, that is, they are called by and operate on a particular instance of an sObject, such as an account or contact. The following are the instance methods for sObjects.
addError
clear
get
getSObjectType()
put

- ApexPages is a class,few methods in this class are
 - addMessage
 - currentPage
 - addMessages


Q: How can I turn my returned List<SObject> into a Set<Id>? Is the best option just a for loop?
Solution a: You can use the Map constructor that accepts an SObject list to do this without consuming a script statement for each element in the List.
For example:

List<SObject> results = Database.query(someSOQL);
Set<Id> resultIds = (new Map<Id,SObject>(results)).keySet();

What this second line does is create a new Map<Id,SObject> from the results list using a special constructor, and then take the map's set of keys via the keySet()
method. Then the map falls out of scope and it's heap space is released, leaving you with a very governor-efficient set.

Solution b:If you are not using Dynamic SOQL,
Set<Id> ids = (new Map<Id, Lead>([SELECT Id FROM Lead])).keySet();
This is how you would do it with Dynamic SOQL but you must cast...
Set<Id> ids = (new Map<Id, Lead>((List<Lead>)Database.query(query))).keySet();


Q: i have to send a mail after every 2 days. how do i implement this?
A: Yes, Time dependent Workflow

Q: Can i pass ID in before insert/update trigger
A: Passing ID in before insert is not possible because there is no record still created.
   In before updated we can pass ID

Q: What is sharing rule and the least restrictive sharing rule
A: Sharing rule must be less restrictive than the ORganization Default Sharing rule.
   OWDs are the baseline security for your Salesforce instance. OWD are used to restirct access. you  grant access through other means like sharing rules, role hierarchy, manual sharing,
   So Sharing rules should not be more restrictive than OWD


Q:Passing parameter from VF page to controller class
<apex:param assignedTo>


Q:Passing parameter from VF page to other VF class
 - through URL
 - Mapobj = ApexPages.currentPage().getParameters();
 - PageReferenceObject.getParameters().put('En',EmployeeName);
 - ApexPages.currentPage().getParameters().get('EN');

Q: what is assignTo in Salesforce?
A setter method that assigns the value of this param to a variable in the associated Visualforce controller.
If this attribute is used, getter and setter methods, or a property with get and set values, must be defined.

Q;What<apex:param> in salesforce?
A parameter for the parent component. The <apex:param> component can only be a child of the following components:
<apex:actionFunction>
<apex:actionSupport>
<apex:commandLink>
<apex:outputLink>
<apex:outputText>
<flow:interview>

Q: What are the types of security in Salesforce.com?
A: http://certifiedondemand.com/overview-of-salesforce-security-model and https://developer.salesforce.com/page/An_Overview_of_Force.com_Security and http://www.terrasky.com/data-security-of-salesforceforce-com-record-level/
   Security is primarily comprised of the following:
Organization Security
Object Security
Record Security
Field Security
Folder Security


Q: Suppose i have related list in a object. How do i avoid showing few specific records in this related list
A:  Use In line VF page concept

Q: can i have custom controller name written in Standardcontroller=''
A: No

Q: what are Best code practices?
A: below are the best practices (https://developer.salesforce.com/page/Apex_Code_Best_Practices)
 #1: Bulkify your Code
 #2: Avoid SOQL Queries or DML statements inside FOR Loops
 #3: Bulkify your Helper Methods
 #4: Using Collections, Streamlining Queries, and Efficient For Loops
 #5: Streamlining Multiple Triggers on the Same Object
 #6: Querying Large Data Sets
 #7: Use of the Limits Apex Methods to Avoid Hitting Governor Limits
 #8: Use @future Appropriately
 #9: Writing Test Methods to Verify Large Datasets
 #10: Avoid Hardcoding IDs

1)If for a object we have set OWD as PRIVATE and at PROFILE level we have VIEW ALL permission enabled.
  Then which all records can a user beloning the profile see?

  Answe r- OWD will be by passed and user can see all records.

2) On a detail page i have a Checkbox. When i click this check box i have to display  a button and when i uncheck this the button should be hidden
   How Can i do this?
 
   Answer - In Std VF page we can Inline VF page using rendered.
 
3) Can we create any number of WF/Arrpoval and validation rules for a object?
   Max we can create 500 WF, out of whihc only 300 can be active
   Max we can create 500 Validation rules, out of whihc only 500 can be active

   4) What are inbound messages?
       HAve to sedn a mail to Salesforce and on receving the email i have insert a reacod how do u do this?

5) I have to deploy 3 class and 2 triggers. My overall Code coverage is 80% but One of the trigger and Class code coverage is 0% Can i deploy the code?
   Even if the overall code coverage is 80% we canot deploy this because.
   Every trigger should have atleast 1% of code coverage. For apex class even if the code coverage is 0% we can deploy but not for gtigger.
   So cannot deploy this .
 
6) Explain how do u provide security with Role and Profiles.
    Consider a object and explain it with respect to it.
Lets say we have Object X, in profile i give Read permission. Which means all users of this profile can read the records of Object X
 - To see the obj/fields we use profiles
 - can give CRUD permission of that obj
 - Is used for providing Structural Type. More like meta data (Record type/object/tab/sobj)
Now Role of a User belonging to this profile is Sales Rep, who comes under Manager.
- Record visisblity in that obj is based on Roles and OWD

7) How many types of sharing is possible in SFDC?
Manual Sharing and Apex Sharing

8) Explain Grant Access through Hierarchy.
This is a feature avaialbe in Force.com
Consider Manager1 who has Emp1 and Emp2 under him
Manager 2 has Emp3 and Emp4 under him
Now Emp1 shares a record with Emp3.
Now Question is can Manager2 See the records shared by Emp1???

Manager2 can see the records only if "Grant Access through Hierarchy " checked.
Other wise Manager 2 cannot view the records.

For standard Objects we cannot change the "Grant Access through Hierarcy". By default is enabled.

No comments:

Post a Comment