Showing posts from 2019

Retrieve IP Address for the Guest Users in Lightning Community

Recently, we received a requirement where we needed to track the IP address of the guest users on the Salesforce Lightning Community.

One of the ways to get the IP address of the current user in Apex is using the following method:

But this method works only for logged in users and gives an error for the guest users. We tried getting the IP address from the cookies also, but it's not a good idea because it is really not necessary that for guest users, you will get the IP address in the cookies always.

At last, we came up with the following workaround to solve this riddle:

1) Create the following apex controller (ViewIPAddressController):
 public class ViewIPAddressController{
    public String ipAddress{get; set;}

    public ViewIPAddressController(){
        //this will work if no caching is in place or
        //user is logged in via secure URL
        ipAddress = ApexPages.currentPage().getHeaders().

Modern JavaScript

Originally named as “LiveScript” but later launched as Javascript, owing to the popularity of the technology at that time, it has become one of the most popular programming languages. Java has been evolving over the last two decades. However, until 2015, Javascript did not have too many enhancements. The JavaScript version most developers are familiar with - ES5) - was published in 2009. Over the last few years, JavaScript has evolved rapidly and the version that we are using has become an old-school version (most of the developers call it “The Dark Ages” of the JS!). So let’s get up to the speed quickly and learn some cool new features of ECMAScript 2015+ also popularly known as ES6+. let In old-school, we were using ‘var’ to declare a variable. That has a huge loophole in the architecture and it’s behaviour. Sometimes it becomes a bottleneck for the developers because ‘var’ does not support block scope. To understand the block scope, see the following piece of script: var x = true; …