Concepts or coding lessons of Salesforce that you can implement easily

Latest Salesforce Interview Questions - 8

136. Can a Apex trigger call a batch class in Salesforce?
Answer:

Yes, we can call a batch class in the trigger as we do in the normal apex code. 

137. Can a trigger make a call to Apex callout method?
Answer:

We can call a callout method in Apex Trigger but the only condition is that it has to be an asynchronous callout because the trigger flow cannot wait on the response received by the callout method.

138. Does Salesforce count calls to System.debug() against the code coverage?
Answer:

No, Salesforce does not count it against the code coverage.

139. What is seeAllData and why it is recommended to avoid using it in Test classes?
Answer:

Test classes run in a different context, i.e. a test class have no idea about the data stored in Salesforce, by setting seeAllData=true =>

@isTest(seeAllData = true)
Enabling this attribute exposes the data from the database to the test class.
It is recommended not to use as the code coverage of you apex class or trigger will now be dependent on the data which is present in org and depending upon that the code coverage may change. 

140. How many characters are allowed in a where clause?
Answer:

We are allowed to use a maximum of 4000 characters in a where clause per SOQL.

141. What are the best practices for test class?
Answer:

There are many considerations while writing a test class few are mentioned below:-
1.   Code coverage should not depend on the existing data in the org, i.e. seeAllData should not be true
2.   For testing trigger and batch class we should do bulk testing with at least 200 records.
3.   Testing should be done for the entire scenario not only for the code coverage.


142. What are the considerations for using Group by clause?
Answer:

There are some fields on sObject which are not supported in grouping.

If a query includes Group by clause then it cannot be used with queryMore() method.

143. What are the authentication access types for a Force.Com Canvas Application?
Answer:

Force.com Canvas Framework: This allows you to take your existing web-based applications and expose/integrate them inside of Salesforce.
Salesforce becomes single screen to access your key applications using Force.com Canvas Framework.

Canvas App Previewer used configure the app & view it.

Authentication Methods:

1. Signed request
2. OAuth 2.0

Canvas App level Authentication Can Be:

1. No Authentication
2. Username / Password
3. SAML
4. SSO
It is 2 sides authentication, together end user gets access

144. When would you use oAuth vs OpenID?
Answer:

Actually both can be used as combination
oAuth : Authorization framework
OpenID : Authentication protocol

145. How many types of Assert Statements are there and what is their purpose?
Answer:

Assert statements are used to compare expected value with the actual value.

There are three types of assert statements :
1.     assertEquals(expVal, actVal); returns true if expVal Matches actVal.
2.     assertNotEqual(expVal, actVal); returns true if expVal does not match actVal.
3.     assertEquals(expVal > actVal); returns true if the condition is satisfied.

146. Give me code free solution to validate duplicate check on combination of First & Last Name?
Answer:

1. Create a formula field to get the concatenation of First & Last Name
2. Create a custom field to hold the value of formula field & declare this field as unique.
3. Create Work flow rule & Field Update action on every record creation/update save the above mentioned formula field value into custom field