Author Archives: Biswajeet

About Biswajeet

Biswajeet is my Name, Success is my Aim and Challenge is my Game. Risk & Riding is my Passion and Hard Work is my Occupation. Love is my Friend, Perfection is my Habit and Smartness is my Style. Smiling is my Hobby, Politeness is my Policy and Confidence is my Power.

Get Salesforce Org Limits Using Apex

Sample Code:

Map<String, System.OrgLimit> orgLimitMap = OrgLimits.getMap();
System.debug('OrgLimitMap-' + orgLimitMap);

for(String olName :orgLimitMap.keySet()) {
    System.OrgLimit orgLimit = orgLimitMap.get(olName);
    System.debug('Org Limit Name: ' + olName);
    System.debug('Org Limit Used:' + orgLimit.getValue());
    System.debug('Org Limit Available:' + orgLimit.getLimit());
}

Salesforce Apex TriggerOperation Enum

The System.TriggerOperation enum has the following values:

  • BEFORE_INSERE
  • AFTER_INSERT
  • BEFORE_UPDATE
  • AFTER_UPDATE
  • BEFORE_DELETE
  • AFTER_DELETE
  • AFTER_UNDELETE

The new Trigger context variable Trigger.operationType will return System.TriggerOperation enum during trigger context.

If you combine this new context variable and the new Apex switch feature, trigger code becomes much easy to implement and understand.

Sample Switch and enum in Triggers:

trigger AccountTrigger on Account(before insert, after insert, before update, after update, before delete, after delete, after undelete) {
    
    switch on Trigger.operationType {
        
        when BEFORE_INSERT {
            //Invoke before insert trigger handler
            system.debug('Before Insert');
        }
        when AFTER_INSERT {
            //Invoke after insert trigger handler
            system.debug('After Insert');
        }
        when BEFORE_UPDATE {
            //Invoke before update trigger handler
            system.debug('Before Update');
        }
        when AFTER_UPDATE {
            //Invoke after update trigger handler
            system.debug('After Update');
        }
        when BEFORE_DELETE {
            //Invoke before delete trigger handler
            system.debug('Before Delete');
        }
        when AFTER_DELETE {
            //Invoke after delete trigger handler
            system.debug('After Delete');
        }
        when AFTER_UNDELETE {
            //Invoke after undelete trigger handler
            system.debug('After Undelete');
        }
    }
}

Create Custom Object From Spreadsheet In Salesforce

Lightning Object Creator is a new tool to create custom object from spreadsheets with just a few clicks.

Step 1:
Go to Setup | Object Manager | Select Custom Object from Spreadsheet

Step 2:
Upload spreadsheets from Microsoft Excel, Google Sheets, or comma-separated value (CSV) files.

Sample Spreadsheet:

Step 3:
After uploading the spreadsheet, Salesforce will automatically detect the fields. You can customize the Salesforce field name and field data type and you also can add field to page layout.

Step 4:
Define object properties and click on Finish button.

Created new custom object from Spreadsheet:

Get Current User Id in Lightning Web Component

To get current user id in Lightning Web Component, we need to import the "@salesforce/user/Id" Salesforce scoped module.

LWC.html

<template>
    <div class="slds-text-heading_large slds-text-align_center">
        User Id : {currentUserId}
    </div>
</template>

LWC.js

import { LightningElement } from 'lwc';
import UserId from '@salesforce/user/Id';

export default class UserInformation extends LightningElement {
    currentUserId = UserId;
}

Output:

Salesforce Lightning Progress Bar With Conditional Theme

Lightning Component:

<aura:component>
    <!--declare handler for render the JS method for Progress bar-->
    <aura:handler name="init" value="{!this}" action="{!c.doInit}"/>
    <!--declare attributes for progress bar value-->
    <aura:attribute name="progress" type="Integer" default="0"/>
    <div class="slds-m-around_xx-large">
        <div class="slds-progress-bar slds-progress-bar_large" aria-valuemin="0" aria-valuemax="100" aria-valuenow="{!v.progress}" role="progressbar">
            <span aura:id="prgBar" class="slds-progress-bar__value" style="{!'width:'+v.progress+'%'}">
                <span class="slds-assistive-text">Progress: {!v.progress}%</span>
            </span>
        </div>
    </div>
</aura:component>

Lightning JS Controller:

({
    //Specifying progress === 100 ? clearInterval(interval) : progress + 5 increases
    //the progress value by 5% and stops the animation when the progress reaches 100%
    //The progress bar is updated every 1000 milliseconds.
    doInit:  function (component, event, helper) {
        var interval = setInterval($A.getCallback(function () {
            var progress = component.get('v.progress');
            var prgBar = component.find("prgBar");
            if(progress >= 0){
                $A.util.addClass(prgBar,'slds-is-low');
            }
            if(progress >= 25){
                $A.util.removeClass(prgBar,'slds-is-low');
                $A.util.addClass(prgBar,'slds-is-medium');
            }
            if(progress >= 50){
                $A.util.removeClass(prgBar,'slds-is-medium');
                $A.util.addClass(prgBar,'slds-is-high');
            }
            if(progress >= 75){
                $A.util.removeClass(prgBar,'slds-is-high');
                $A.util.addClass(prgBar,'slds-is-critical');
            }
            component.set('v.progress', progress === 100 ? clearInterval(interval) : progress + 5);
        }), 1000);
    }
})

Lightning Style:

.THIS .slds-is-low {
    background-color: green!important;
}
.THIS .slds-is-medium{
    background-color: yellow!important;
}
.THIS .slds-is-high{
    background-color: orange!important;
}
.THIS .slds-is-critical{
    background-color: red!important;
}

Output: