Salesforce Lightning Confirm Dialog Box

Lightning Component:

<aura:component implements="flexipage:availableForAllPageTypes,force:appHostable">
    
    <!--Attributes-->
    <aura:attribute name="showConfirmDialog" type="boolean" default="false"/>
    
    <!--Component Start-->
    <div class="slds-m-around_xx-large">
        <lightning:button name="delete" variant="brand" label="Delete" onclick="{!c.handleConfirmDialog}"/>
        
        <aura:if isTrue="{!v.showConfirmDialog}">
            <!--Modal Box Start-->
            <div role="dialog" class="slds-modal slds-fade-in-open ">
                <div class="slds-modal__container">
                    <!--Modal Box Header Start-->
                    <header class="slds-modal__header">
                        <h1 class="slds-text-heading--medium">Confirmation</h1>
                    </header>
                    <!--Modal Box Header End-->
                    
                    <!--Modal Box Content Start-->
                    <div class="slds-modal__content slds-p-around--medium">
                        <center><b>Are you sure you want to delete this item?</b></center>
                    </div>
                    <!--Modal Box Content End-->
                    
                    <!--Modal Box Button Start-->
                    <footer class="slds-modal__footer">
                        <lightning:button name='No' label='No' onclick='{!c.handleConfirmDialogNo}'/>
                        <lightning:button variant="brand" name='Yes' label='Yes' onclick='{!c.handleConfirmDialogYes}'/>
                    </footer>
                    <!--Modal Box Button End-->
                </div>
            </div>
            <div class="slds-backdrop slds-backdrop--open"></div>            
        </aura:if>
    </div>
    <!--Component End-->
</aura:component>

Lightning JS Controller:

({
    handleConfirmDialog : function(component, event, helper) {
        component.set('v.showConfirmDialog', true);
    },
    
    handleConfirmDialogYes : function(component, event, helper) {
        console.log('Yes');
        component.set('v.showConfirmDialog', false);
    },
    
    handleConfirmDialogNo : function(component, event, helper) {
        console.log('No');
        component.set('v.showConfirmDialog', false);
    },
})

Output:

Disable Caching Setting During Lightning Component Development

  • Click Setup (Enter Session in the Quick Find box) | Administration Setup | Security Controls | Session Settings
  • Locate the Caching section.
  • Select the “Enable secure and persistent browser caching to improve performance”.
  • Click Save

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');
        }
    }
}