Concepts or coding lessons of Salesforce that you can implement easily

Subtraction of Two Time Fields No Longer Produces Negative Results in Salesforce

Previously, subtraction of two time datatype fields in Salesforce could result in a negative value.

Starting in the Summer '18 release, subtraction is always a positive value on a 24-hour clock.

Example:


When calculating the number of hours a business is open, you use the following formula (also taking into account each hour is 3,600,000 milliseconds):

(ClosedTime - OpenTime) / 3600000

ClosedTime = 5 PM, OpenTime = 8 AM, 
then result is ClosedTime - OpenTime = 9 hours

ClosedTime = 5 AM, OpenTime = 7 AM, 
then result is ClosedTime - OpenTime = 22 hours

ClosedTime = 5 AM, OpenTime = 11 PM, 
then result is ClosedTime - OpenTime = 6 hours


Latest Salesforce Interview Questions and Answers:

Salesforce Interview Questions - Part 1

Salesforce Interview Questions - Part 2

Salesforce Interview Questions - Part 3

Salesforce Interview Questions - Part 4

Salesforce Interview Questions - Part 5

Salesforce Interview Questions - Part 6

Salesforce Interview Questions - Part 7

Salesforce Interview Questions - Part 8

More Salesforce Blogs:

Check out Salesforce Daily Limit Only in 5 Simplest Steps
Learning Pagination In Salesforce Is Not Difficult At All ! You Just Need 3 Easy Steps
How To Learn Get Field Values From Visualforce Page To Apex Class Controller Without Losing Your Mind
Main Difference Between ISBLANK And ISNULL in Salesforce
How To Get Total Amount Of Records Processed In Batch Job In 10 Minutes And Still Look Your Best 
Export VisualForce Data into Excel Sheet in 3 Easiest Steps
7 Easy Steps to Generate Apex Class From WSDL In Salesforce
Simplest Way To Find Number of Days Between Two Dates in Salesforce
3 Easy Steps To Send Emails With Attachment From Your Apex Class In Salesforce
How Insert Comma In Formula Fields Can Help You Improve Your Productivity
Simple Guidance For You In Access Of Subquery Field Value Using Apex - Upwards Traversal.
Access Subquery Field Value Using Apex in 2 Easy Steps- Downwards Traversal

How Learning Enable Inline Editing In Visual Force Pages Could Save Your Money And Time


Enjoy! If you have any questions, comments etc. please feel free to let me know. As always, please feel free to get in touch me as I would be more than happy to assist you with any of your Salesforce development needs.

Difference Between Indirect Lookup and External Lookup In Salesforce

Indirect Lookup Relationship

External Lookup Relationship

This type is basically when Standard/ Custom object as a parent and an External object as a child.
This type is basically when an External object as a parent and external/ standard/ custom object as a child.
Only objects that have a custom field with the External ID and Unique attributes are available as parent objects in indirect lookup relationships.
The External ID standard field as parent field matching
Use Case:
Use Case :
When the external data doesn’t include Salesforce record IDs.
Use an external lookup relationship when a parent is an external object.
Use the External Id as a link between External & SFDC object.

Ex:
Ex:
Account record (parent standard object) displays a related list of SAP sales orders (child external object) with matching customer IDs that aren’t Salesforce IDs.
External product catalog item (parent external object) displays a related list of support cases (child standard object)

Latest Salesforce Interview Questions and Answers:

Salesforce Interview Questions - Part 1

Salesforce Interview Questions - Part 2

Salesforce Interview Questions - Part 3

Salesforce Interview Questions - Part 4

Salesforce Interview Questions - Part 5

Salesforce Interview Questions - Part 6

Salesforce Interview Questions - Part 7

Salesforce Interview Questions - Part 8


More Salesforce Blogs:

Check out Salesforce Daily Limit Only in 5 Simplest Steps
Learning Pagination In Salesforce Is Not Difficult At All ! You Just Need 3 Easy Steps
How To Learn Get Field Values From Visualforce Page To Apex Class Controller Without Losing Your Mind
Main Difference Between ISBLANK And ISNULL in Salesforce
How To Get Total Amount Of Records Processed In Batch Job In 10 Minutes And Still Look Your Best 
Export VisualForce Data into Excel Sheet in 3 Easiest Steps
7 Easy Steps to Generate Apex Class From WSDL In Salesforce
Simplest Way To Find Number of Days Between Two Dates in Salesforce
3 Easy Steps To Send Emails With Attachment From Your Apex Class In Salesforce
How Insert Comma In Formula Fields Can Help You Improve Your Productivity
Simple Guidance For You In Access Of Subquery Field Value Using Apex - Upwards Traversal.
Access Subquery Field Value Using Apex in 2 Easy Steps- Downwards Traversal

How Learning Enable Inline Editing In Visual Force Pages Could Save Your Money And Time



Enjoy! If you have any questions, comments etc. please feel free to let me know. As always, please feel free to get in touch me as I would be more than happy to assist you with any of your Salesforce development needs.

How to get current month using apex in Salesforce?

Sample Apex Code:


Integer Month = Date.Today().Month();

Latest Salesforce Interview Questions and Answers:

Salesforce Interview Questions - Part 1

Salesforce Interview Questions - Part 2

Salesforce Interview Questions - Part 3

Salesforce Interview Questions - Part 4

Salesforce Interview Questions - Part 5

Salesforce Interview Questions - Part 6

Salesforce Interview Questions - Part 7

Salesforce Interview Questions - Part 8



More Salesforce Blogs:

Check out Salesforce Daily Limit Only in 5 Simplest Steps
Learning Pagination In Salesforce Is Not Difficult At All ! You Just Need 3 Easy Steps
How To Learn Get Field Values From Visualforce Page To Apex Class Controller Without Losing Your Mind
Main Difference Between ISBLANK And ISNULL in Salesforce
How To Get Total Amount Of Records Processed In Batch Job In 10 Minutes And Still Look Your Best 
Export VisualForce Data into Excel Sheet in 3 Easiest Steps
7 Easy Steps to Generate Apex Class From WSDL In Salesforce
Simplest Way To Find Number of Days Between Two Dates in Salesforce
3 Easy Steps To Send Emails With Attachment From Your Apex Class In Salesforce
How Insert Comma In Formula Fields Can Help You Improve Your Productivity
Simple Guidance For You In Access Of Subquery Field Value Using Apex - Upwards Traversal.
Access Subquery Field Value Using Apex in 2 Easy Steps- Downwards Traversal

How Learning Enable Inline Editing In Visual Force Pages Could Save Your Money And Time


Enjoy! If you have any questions, comments etc. please feel free to let me know. As always, please feel free to get in touch me as I would be more than happy to assist you with any of your Salesforce development needs.

What is the use of nextStartDate in Salesforce?




Starting from the specified target date returns the next date when business hours are open.
If the specified target date falls within business hours, this target date is returned.


Let say, you have specified the hours when your support team is available to serve your customers.

And there is Case open outside the business hours then what will be nextStartDate of your Business Hours? See below...

Syntax:


public static Datetime nextStartDate(String businessHoursId, Datetime targetDate)

The following example I am using System.Today() as a  target date.
Sample Apex Code:


// Get the default business hours
BusinessHours busshrs = [SELECT Id FROM BusinessHours WHERE IsDefault = true];
// If it is within the business hours. The returned time will be in the local time zone
Datetime nextStart = BusinessHours.nextStartDate(busshrs.id, System.today());
System.debug('Next Business Hours Start Date is => ' + nextStart);

Example/Use Case:


Business hours for your Salesforce Org are 9 AM to 6 PM. So there are 2 results based on below:

1. If you execute the above code within the business hours, then it will return today's date.
2. If you execute the above code outside the business hours, then it will return next open business date.


Latest Salesforce Interview Questions and Answers:



More Salesforce Blogs:

Check out Salesforce Daily Limit Only in 5 Simplest Steps
Learning Pagination In Salesforce Is Not Difficult At All ! You Just Need 3 Easy Steps
How To Learn Get Field Values From Visualforce Page To Apex Class Controller Without Losing Your Mind
Main Difference Between ISBLANK And ISNULL in Salesforce
How To Get Total Amount Of Records Processed In Batch Job In 10 Minutes And Still Look Your Best 
Export VisualForce Data into Excel Sheet in 3 Easiest Steps
7 Easy Steps to Generate Apex Class From WSDL In Salesforce
Simplest Way To Find Number of Days Between Two Dates in Salesforce
3 Easy Steps To Send Emails With Attachment From Your Apex Class In Salesforce
How Insert Comma In Formula Fields Can Help You Improve Your Productivity
Simple Guidance For You In Access Of Subquery Field Value Using Apex - Upwards Traversal.
Access Subquery Field Value Using Apex in 2 Easy Steps- Downwards Traversal

How Learning Enable Inline Editing In Visual Force Pages Could Save Your Money And Time


Enjoy! If you have any questions, comments etc. please feel free to let me know. As always, please feel free to get in touch me as I would be more than happy to assist you with any of your Salesforce development needs.

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