Lightning Component Actions

Introductions

In this blog, I am going to explain how to custom actions to customize lightning and  Salesforce1 experiences with both global actions and quick actions. Global actions are not associated with any object means you can insert data that is not going to establish any relations other record and Object-specific actions are associated with the object so it allows creating records that have automatic relationships to other records, make updates to specific records. To available Lightning component as actions, you need to implement either the force: LightningQuickAction or force: LightningQuickActionWithoutHeader interfaces.Add the force:hasRecordId interface to a Lightning component to enable the component to be assigned the ID of the current record. When we implement the force:lightningQuickAction interface display in a panel with standard action controls, such as a Cancel button. If instead, you want complete control over the user interface, use the force: lightningQuickActionWithoutHeader interface. Components that implement the force:lightningQuickActionWithoutHeader display in a panel without additional controls and are expected to provide a complete user interface for the action.

Object-Specific Actions
What we are going to do it here, we will create a quick action that is going to create a quote from the opportunity. Create an apex class as shown below and the apex class is used to communicate to server-side actions to save the Quote.

Go to developer console and create a new lightning component name ” Quick Quote” with below code

Here is Lightning component controller code.

The createQuote action handler method will do the following action

  • Invoke server action to save the quote by calling component.get(“c.saveQuote”) from the apex class .
  • Defines a callback function to handle the server response.
  • Enqueues the server action by calling” $A.enqueueAction(saveAction)
  • handleCancel Closes the action panel by firing the force:closeQuickAction event.
  • Displays a “toast” message that the Quote was created by firing the force:showToast event.

Go to Opportunity and create an action as shown below.

Add it to the opportunity  Salesforce1 and Lightning Experience Actions section on the page layouts to create quote by using actions.

 

Global Actions

Now we are going to create global actions that allow users to create the new user from the global action.
create a new apex class “CreateNewUser” with the below code.

Go to developer console and create a new lightning component “CreateNewUser” with below code.

Here is the component controller.

Go to Global action from the setup menu and create a new global action as shown below.

Go to publisher layout from the setup menu and add the lightning component create to the layout as shown below.

You can access global action from salesforce global header.