Aura Components in Salesforce are reusable blocks of code used to build user interfaces, while Global Actions allow users to perform tasks like creating records or logging calls from anywhere in the system. Both features enhance user productivity and provide dynamic interaction across Salesforce apps and platforms.

Salesforce Lightning provides a modern user interface and a powerful component-based framework for building dynamic applications. One of the key features of this framework is the ability to create Aura Components and use them as Global Actions. This tutorial will guide you step-by-step on how to create an Aura Component and expose it as a Global Action, making it accessible from anywhere within Salesforce, such as the Global Actions menu or within a Salesforce Flow.

What are Aura Components and Global Actions?

  • Aura Components: Reusable units of code that represent a piece of the user interface. They are part of the Lightning Component framework, allowing developers to build responsive and dynamic applications.
  • Global Actions: Quick actions that are accessible from the Salesforce header, enabling users to perform tasks like creating records or logging calls without navigating away from their current page.

By combining Aura Components with Global Actions, you can create custom functionality that users can access globally within Salesforce.

Creating Salesforce aura component global action- Step-by-Step Guide

Step 1: Create an Aura Component

  1. Navigate to the Developer Console:
    • Log in to your Salesforce org.
    • Click on the gear icon in the upper-right corner and select Developer Console.
  2. Create a New Aura Component:
    • In the Developer Console, go to File > New > Lightning Component.
    • Name your component, for example, GlobalActionComponent.
    • Check Implements: forceto make it available as a quick action.
    • Click Submit.
  3. Design the Component:
    • In the component’s markup file (.cmp), add the desired UI elements.
<aura:component implements="force:lightningQuickAction" access="global">
    <aura:attribute name="message" type="String" default="Hello, World!"/>
    <lightning:card title="Global Action Component">
        <p>{!v.message}</p>
        <lightning:button label="Close" onclick="{!c.closeAction}"/>
    </lightning:card>
</aura:component>
  1. Add a Controller:
    • Create a client-side controller (.js file) to handle actions:
({
    closeAction : function(component, event, helper) {
        $A.get("e.force:closeQuickAction").fire();
    }
})
  1. Save All Files:
    • Ensure that all files (.cmp.js, and .css if used) are saved.

Step 2: Create a Global Action

  1. Navigate to Setup:
    • Click on the gear icon and select Setup.
  2. Go to Global Actions:
    • In the Quick Find box, type Global Actions and select Global Actions under Platform Tools > User Interface.
  3. Create a New Action:
    • Click New Action.
    • Set Action Type to Lightning Component.
    • In Lightning Component, select your component (c:GlobalActionComponent).
    • Set Label and Name, e.g., Global Action Component.
    • Click Save.

Step 3: Add the Global Action to the Publisher Layout

  1. Navigate to Publisher Layouts:
    • In Setup, search for Publisher Layouts.
  2. Edit the Layout:
    • Click Edit next to the Global Publisher Layout.
  3. Add the Action:
    • From the Actions palette, drag your new action to the Publisher Actions section.
  4. Save the Layout.

Step 4: Test the Global Action

  1. Access the Global Actions Menu:
    • Click on the + icon (Global Actions) in the Salesforce header.
  2. Select Your Action:
    • Find and click on Global Action Component.
  3. Verify the Component Loads:
    • The Aura Component should display with your message and the Close button.

Step 5: Use the Aura Component in a Flow (Optional)

Using Aura Components inside a Flow can enhance the user experience.

  1. Create a Flow:
    • In Setup, search for Flows and click New Flow.
  2. Select Screen Flow:
    • Choose Screen Flow and click Create.
  3. Add a Screen Element:
    • Drag a Screen element onto the canvas.
  4. Add Your Component to the Screen:
    • In the screen’s Components section, search for your component.
    • Drag Global Action Component into the screen.
  5. Configure the Screen:
    • Set Label and other properties as needed.
  6. Save and Activate the Flow.
  7. Test the Flow:
    • Run the flow and verify that the component displays correctly.

Conclusion

By following these steps, you’ve successfully created an Aura Component and used it as a Global Action in Salesforce. This powerful combination allows you to provide users with custom functionality accessible from anywhere within the platform. Experiment with different components and actions to tailor the experience to your organization’s needs.

Additional Tips

  • Best Practices:
    • Always implement proper error handling in your components.
    • Use the force:hasRecordId interface if you need context about the record.
  • Security Considerations:
    • Ensure that the component’s access attribute is set appropriately (global for global access).
    • Be mindful of the data exposed through the component.