About Me

My photo
PLANO, Texas, United States

Thursday, April 29, 2021

Time Conversion for different time-zone

The purpose of this article is to explain different methods of timezone classes, and how they can be used. Even though Salesforce used to convert the dates based on the logged-in user timezone, however, you wanted to see a time to a different timezone, you can do it with the TimeZone class. 

You can use below methods to calculate time in different time zones. 

TimeZone Methods

  1. getDisplayName() - Returns this time zone’s display name.
  2. getID() -Returns this time zone’s ID.
  3. getOffset(date) -Returns the time zone offset, in milliseconds, of the specified date to the GMT time zone.
  4. getTimeZone(timeZoneIdString) -Returns the time zone corresponding to the specified time zone ID.
  5. toString() -Returns the string representation of this time zone.

In the above methods, getOffset() method is very important. An offset is the number of hours or minutes a certain time zone is ahead of or behind GMT. A time zone’s offset can change throughout the year because of Daylight Saving Time.

User Case

Let’s say, there is a sales Rep, who calls customers and book appointments with experts to assist their needs. Suppose the Sales Rep is sitting in Dallas which is in Central time-zone and he called to a customer who is sitting in (New York Eastern time zone). While booking the appointment, the customer will suggest time as per his local time zone. In that case, sales Rep needs to convert time to his timezone. So if a user suggests 12 PM EST, it will be 11 AM CST. Using the below logic, sales rep no need to worry about this conversion. 

public static DateTime getConvertedTime(DateTime anyDateTime, string sourceTimezoneId, string targetTimezoneId){

        //get source time-zone corresponding to the specified time zone ID

        TimeZone sourceTimeZone = Timezone.getTimeZone(sourceTimezoneId); 

        //get source time-zone offset in milliseconds

        Integer sourceGMT_Time=sourceTimeZone.getOffset(anyDateTime);

        //get Target time-zone corresponding to the specified time zone ID

        TimeZone targetTimeZone = Timezone.getTimeZone(targetTimezoneId);

        //get target time-zone offset  in milliseconds

        integer targetGMT_Time = targetTimeZone.getOffset(anyDateTime);

        //Get the difference in milliseconds

        Integer differenceInMs = targetGMT_Time- sourceGMT_Time;

        //Convert difference into minutes    

        Integer differenceInSec= differenceInMs/1000;

        //Add difference to the time, to get time in target timezone

        DateTime timeInTargetTimeZone = anyDateTime.addMinutes(differenceInSec);

        return timeInTargetTimeZone;

}                         


Reference: Salesforce Documentation 

Friday, April 23, 2021

Schedule Event Monitoring

How to Schedule Event Monitoring in Salesforce Einstein Analytics?

  • Go to data manager 

        
  • Go to Dataflows & Recipes under Monitor
        
  • Go to Event Monitoring App and click on Schedule
        
  • Schedule the accordingly 
    

Thursday, April 15, 2021

Aura Interfaces

Interfaces define a component’s shape by defining attributes, events, or methods that any implementing component contains. 
  • To use an interface, a component must implement it.

  • An interface can’t be used directly in markup.

Types of Interfaces

Broadly, there are two types of Interfaces, one is in-build interface provided by framework which can be used for different and the other is a custom that developers can build themself.

In-build Interface

Theura framework provides in-build interfaces which you can implements in your custom component for different purposes. Below are a few in build interface:

  1. force:appHostable – The force:appHostable interface makes the component available for use as a custom tab. This interface is a marker interface. A marker interface is a signal to the component’s container to add the interface’s behavior to the component. You don’t need to implement any specific methods or attributes in your component, you simply add the interface name to the component’s implements attribute.

  2. flexipage:availableForAllPageTypes-To make your component available for record pages and any other type of page, implement the flexipage:availableForAllPageTypes interface.

  3. flexipage:availableForRecordHome- To make your component available for record pages only, implement the flexipage:availableForRecordHome interface.

  4. force:lightningQuickAction- Add the force:lightningQuickAction interface to a Lightning component to allow it to be used as a custom action

  5. forceCommunity:availableForAllPageTypes- To appear in Experience Builder, a component must implement the forceCommunity:availableForAllPageTypes interface.

  6. force:hasRecordId-Add the force:hasRecordId interface to an Aura component to enable the component to be assigned the ID of the current record. The current record ID is useful if the component is used on a Lightning record page, as an object-specific custom action or action override in Lightning Experience or the Salesforce mobile app, and so on. This interface has no effect except when used within Lightning Experience, the Salesforce mobile app, and Aura-based Experience Builder sites.

You can find more build interface below: https://developer.salesforce.com/docs/component-library/overview/interfaces 

Custom Interface

You can create your own interface using <aura:interface> tag. An interface can contain only these tags:

  • <aura:attribute> tags to define the interface’s attributes.

  • <aura:registerEvent> tags to define the events that it may fire.

  • <aura: method> tags to define the events that it may fire.


<aura:interface>

    <aura:attribute name="value" type="String" />

    <aura:registerEvent name="onItemSelected" type="ui:response" description="The event fired when the user selects an item" />

    <aura:method name="methodFromInterface">

        <aura:attribute name="stringAttribute" type="String" default="default string" />

    </aura:method>

</aura:interface>