Salesforce Lightning Loading Spinner

lightning:spinner displays an animated spinner image to indicate that a feature is loading. This component can be used when retrieving data or anytime an operation doesn’t immediately complete.

We can control lightning loading spinner using aura:waiting and aura:donewaiting standard events. Both aura:waiting and aura:doneWaiting are application level events.

aura:waiting: Indicates that the app is waiting for a response to a server request.

aura:donewaiting: Indicates that the app is done waiting for a response to a server request.

Example:

Apex Controller:

public class SampleAuraController {
    
    @AuraEnabled
    public static String getMessage() {
        return 'Hello World!!';
    }
}

Lightning Component:

<!--Sample.cmp--> 
<aura:component controller="SampleAuraController" implements="flexipage:availableForAllPageTypes,force:appHostable">
    
    <!--Declare Handlers-->
    <aura:handler event="aura:waiting" action="{!c.handleShowSpinner}"/>
    <aura:handler event="aura:doneWaiting" action="{!c.handleHideSpinner}"/>
    
    <!--Declare Attributes-->
    <aura:attribute name="showSpinner" type="boolean" default="false"/>
    
    <!--Component Start--> 
    <div class="slds-m-around--xx-large">
         <aura:if isTrue="{!v.showSpinner}">
        <lightning:spinner alternativeText="Loading, Please Wait..." title="Loading, Please Wait..." variant="brand" size="large"/>
             </aura:if>
        <lightning:button label="Click Me" variant="brand" onclick="{!c.handleClick}"/>
    </div>
    <!--Component End-->
</aura:component>

Lightning JS Controller:

({
    //Handle Button click 
    handleClick: function (component, event, helper) {
        var action = component.get('c.getMessage');
        action.setCallback(this,function(response){
            var state = response.getState();
            if (state === "SUCCESS") {
                var result = response.getReturnValue();
                console.log('result -' + result)
            }
        });
        $A.enqueueAction(action); 
    },
    
    //Call by aura:waiting event  
    handleShowSpinner: function(component, event, helper) {
        component.set("v.showSpinner", true); 
    },
    
    //Call by aura:doneWaiting event 
    handleHideSpinner : function(component,event,helper){
        component.set("v.showSpinner", false);
    }
})

Output:

Global Picklist Value Set in Salesforce

Global Picklist or Picklist Value Set is an Universal Picklist Values, which can be applied to any custom picklist fields that you create both on standard and custom objects.

Lets take an example, I have an object called “Student” and “Student Application” in these two object I have to create a picklist field called “Language”. So, here I’ve created a “Picklist Value Set” and used it on both object “Student Application”.

Click Setup || App Setup || Create || Picklist Value Set || Click ‘New’

Create “Language” Picklist Value Set:

Create “Language” Picklist from Picklist Value Set in “Student” and “Student Application” object:

Check “Language” Picklist Value Set, where it is used:

Note: You can have up to 500 picklist global value sets in an org. Each global value set, or restricted picklist, can contain a mix of 1,000 active and inactive values. Unrestricted picklists can have up to 1,000 active values. There’s no limit on the number of custom picklists that use global picklist value sets.

Picklist Value Set Considerations:

  • Validation rules are still defined at the field level, and are not part of the Picklist Value Set definition. This means, you can have the Business Unit picklist field on Account to respect a validation rule; and the same field on the Contact object not.
  • It is possible to create a mutli-select picklist field using a Picklist Value Set definition. However, in such cases the “replace” functionality available on regular picklist fields are not available.
  • Also, a picklist field created based on a Picklist Value Set cannot be used as a dependent picklist. It can still be used as a controlling picklist field. This is a known and documented limitation.

Webservice Callout From Apex Trigger

In certain scenarios, we need to make the webservice callout from the apex trigger to call an external webservice. We cannot call external web services synchronously from triggers, because calling a web service synchronously from triggers will hold up the database transaction until the callout completed. This will impact performance for other transactions. In this scenario we can invoke callouts from triggers by encapsulating the callouts in @future methods. Here is an example, how to invoke webservice callouts from trigger.

Apex Class:

public class LeadTriggerHandler {
    
    @future (callout=true)
    public static void sendLeadInfo(string firstName, string lastName, string email) {
        try{
            HttpRequest request = new HttpRequest();
            HttpResponse response = new HttpResponse();
            Http http = new Http();
            
            request.setEndpoint('Your Endpoint URL');
            request.setHeader('Content-Type','application/json'); 
            request.setMethod('POST');
            request.setBody('fname='+EncodingUtil.urlEncode(firstName, 'UTF-8')+'&lname='+EncodingUtil.urlEncode(lastName, 'UTF-8')
                            '&email='+EncodingUtil.urlEncode(email, 'UTF-8'));
            request.setCompressed(true);
            
            response = http.send(request);
            if (response.getStatusCode() == 200) {
                System.debug('Response-' + response);
            }
        }
        catch(System.CalloutException e){
            System.debug('Error-' + e.getMessage());   
        }
    }
}

Apex Trigger:

trigger LeadTrigger on Lead (after insert) {
    
    for (Lead objLead : Trigger.new) {
        //make webservice callout 
        LeadTriggerHandler.sendLeadInfo(objLead.FirstName, objLead.LastName, objLead.Email);
    }
}

$Action Global Variable in Salesforce

$Action is a global variable. All objects support basic actions, such as new, clone, view, edit, list, and delete. The $Action global also references actions available on many standard objects.

Example:

<apex:page standardController="Account">
    
    <!--Create Account New Record-->
    <apex:outputLink value="{!URLFOR($Action.Account.New)}">
        Creating New Account
    </apex:outputLink>
    
    <!--Edit Account Record -->
    <apex:outputLink value="{!URLFOR($Action.Account.Edit, Account.Id)}">
        Editing record
    </apex:outputLink>
    
    <!--Delete Account Record-->
    <apex:outputLink value="{!URLFOR($Action.Account.Delete, Account.Id)}">
        Deleting Account Record
    </apex:outputLink>
    
    <!--Navigate to Account List view-->
    <apex:outputLink value="{!URLFOR($Action.Account.List, $ObjectType.Account)}">
        Go to the Account List View
    </apex:outputLink>
    
    <!--Navigate to Account Tab-->
    <apex:outputLink value="{!URLFOR($Action.Account.Tab, $ObjectType.Account)}">
        Go to the Account tab
    </apex:outputLink>
</apex:page>

You can reference following actions with the $Action global variable and the objects on which you can perform those actions.

Value Description Objects
Accept Accept a record.
  • Ad group
  • Case
  • Event
  • Google campaign
  • Keyword
  • Lead
  • Search phrase
  • SFGA version
  • Text ad
Activate Activate a contract. Contract
Add Add a product to a price book. Product2
AddCampaign Add a member to a campaign. Campaign
AddInfluence Add a campaign to an opportunity’s list of influential campaigns. Opportunity
AddProduct Add a product to price book. OpportunityLineItem
AddToCampaign Add a contact or lead to a campaign.
  • Contact
  • Lead
AddToOutlook Add an event to Microsoft Outlook. Event
AdvancedSetup Launch campaign advanced setup. Campaign
AltavistaNews Launch www.altavista.com/news/.
  • Account
  • Lead
Cancel Cancel an event. Event
CaseSelect Specify a case for a solution. Solution
ChangeOwner Change the owner of a record.
  • Account
  • Ad group
  • Campaign
  • Contact
  • Contract
  • Google campaign
  • Keyword
  • Opportunities
  • Search phrase
  • SFGA version
  • Text ad
ChangeStatus Change the status of a case.
  • Case
  • Lead
ChoosePricebook Choose the price book to use. OpportunityLineItem
Clone Clone a record.
  • Ad group
  • Asset
  • Campaign
  • Campaign member
  • Case
  • Contact
  • Contract
  • Event
  • Google campaign
  • Keyword
  • Lead
  • Opportunity
  • Product
  • Search phrase
  • SFGA version
  • Text ad
  • Custom objects
CloneAsChild Create a related case with the details of a parent case. Case
CloseCase Close a case. Case
Convert Create a new account, contact, and opportunity using the information from a
lead.
Lead
ConvertLead Convert a lead to a campaign member. Campaign Member
Create_Opportunity Create an opportunity based on a campaign member. Campaign Member
Decline Decline an event. Event
Delete Delete a record.
  • Ad group
  • Asset
  • Campaign
  • Campaign member
  • Case
  • Contact
  • Contract
  • Event
  • Google campaign
  • Keyword
  • Lead
  • Opportunity
  • Opportunity product
  • Product
  • Search phrase
  • SFGA version
  • Solution
  • Task
  • Text ad
  • Custom objects
DeleteSeries Delete a series of events or tasks.
  • Event
  • Task
DisableCustomerPortal Disable a Customer Portal user. Contact
DisableCustomerPortalAccount Disable a Customer Portal account. Account
DisablePartnerPortal Disable a Partner Portal user. Contact
DisablePartnerPortalAccount Disable a Partner Portal account. Account
Download Download an attachment.
  • Attachment
  • Document
Edit Edit a record.
  • Ad group
  • Asset
  • Campaign
  • Campaign member
  • Case
  • Contact
  • Contract
  • Event
  • Google campaign
  • Keyword
  • Lead
  • Opportunity
  • Opportunity product
  • Product
  • Search phrase
  • SFGA version
  • Solution
  • Task
  • Text ad
  • Custom objects
EditAllProduct Edit all products in a price book. OpportunityLineItem
EnableAsPartner Designate an account as a partner account. Account
EnablePartnerPortalUser Enable a contact as a Partner Portal user. Contact
EnableSelfService Enable a contact as a Self-Service user. Contact
FindDup Display duplicate leads. Lead
FollowupEvent Create a follow-up event. Event
FollowupTask Create a follow-up task. Event
HooversProfile Display a Hoovers profile.
  • Account
  • Lead
IncludeOffline Include an account record in Connect Offline. Account
GoogleMaps Plot an address on Google Maps.
  • Account
  • Contact
  • Lead
GoogleNews Display www.google.com/news.
  • Account
  • Contact
  • Lead
GoogleSearch Display www.google.com.
  • Account
  • Contact
  • Lead
List List records of an object.
  • Ad group
  • Campaign
  • Case
  • Contact
  • Contract
  • Google campaign
  • Keyword
  • Lead
  • Opportunity
  • Product
  • Search phrase
  • SFGA version
  • Solution
  • Text ad
  • Custom objects
LogCall Log a call. Activity
MailMerge Generate a mail merge. Activity
ManageMembers Launch the Manage Members page. Campaign
MassClose Close multiple cases. Case
Merge Merge contacts. Contact
New Create a new record.
  • Activity
  • Ad group
  • Asset
  • Campaign
  • Case
  • Contact
  • Contract
  • Event
  • Google campaign
  • Keyword
  • Lead
  • Opportunity
  • Search phrase
  • SFGA version
  • Solution
  • Task
  • Text ad
  • Custom objects
NewTask Create a task. Task
RequestUpdate Request an update.
  • Contact
  • Activity
SelfServSelect Register a user as a Self Service user. Solution
SendEmail Send an email. Activity
SendGmail Open a blank email in Gmail.
  • Contact
  • Lead
Sort Sort products in a price book. OpportunityLineItem
Share Share a record.
  • Account
  • Ad group
  • Campaign
  • Case
  • Contact
  • Contract
  • Google campaign
  • Keyword
  • Lead
  • Opportunity
  • Search phrase
  • SFGA version
  • Text ad
Submit for Approval Submit a record for approval.
  • Account
  • Activity
  • Ad group
  • Asset
  • Campaign
  • Campaign member
  • Case
  • Contact
  • Contract
  • Event
  • Google campaign
  • Keyword
  • Lead
  • Opportunity
  • Opportunity product
  • Product
  • Search phrase
  • SFGA version
  • Solution
  • Task
  • Text ad
Tab Access the tab for an object.
  • Ad group
  • Campaign
  • Case
  • Contact
  • Contract
  • Google campaign
  • Keyword
  • Lead
  • Opportunity
  • Product
  • Search phrase
  • SFGA version
  • Solution
  • Text ad
View View a record.
  • Activity
  • Ad group
  • Asset
  • Campaign
  • Campaign member
  • Case
  • Contact
  • Contract
  • Event
  • Google campaign
  • Keyword
  • Lead
  • Opportunity
  • Opportunity product
  • Product
  • Search phrase
  • SFGA version
  • Solution
  • Text ad
  • Custom objects
ViewAllCampaignMembers List all campaign members. Campaign
ViewCampaignInfluenceReport Display the Campaigns with Influenced Opportunities report. Campaign
ViewPartnerPortalUser List all Partner Portal users. Contact
ViewSelfService List all Self-Service users. Contact
YahooMaps Plot an address on Yahoo! Maps.
  • Account
  • Contact
  • Lead
YahooWeather Display http://weather.yahoo.com/. Contact