GridMate offers out of the box a set of actions like Mass Assign, Mass Approve...However there is some situation where a custom component is required to address the business needs like implementing a specific logic or calling an external system.
To address this type of use cases, GridMate defines an interface which is a set of properties and events.
Aura Properties
<!-- The object of the grid --><aura:attributename="relatedObjectName"type="String"access="global" /><!-- The list of displayed columns --><aura:attributename="columns"type="Object[]"access="global" /><!-- The list of selected items --><aura:attributename="selectedItems"type="Object[]"access="global" /><!-- The Id of the master record (record page or master record) --><aura:attributename="recordId"type="String"access="global" />
Aura Events
<!-- Event to be fired when the action is executed successfully--><aura:registerEventname="onsuccess"type="c:DataGridActionEvent" /><!-- Event to be fired when the user cancel the action--><aura:registerEventname="oncancel"type="c:DataGridActionEvent" />
Aura Implementation
Aura Component
Let's say that we want to move to close date by one day for the selected items. Let's go ahead and start our custom action using an Aura component.
This action will be triggered from an Opportunity grid. Let's create an Aura component MoveCloseDateComponent. The component has all the required properties described above.
Also the component will fire onsucess or oncancel based on the user flow when the user submit the transaction or cancel the screen.
({handleSubmit:function (component, event, helper) {component.set('v.isWorking',true);//Submit the action to the Salesforcelet action =component.get('c.moveCloseDate');action.setParams({ idList:component.get('v.selectedItems').map((x) =>x.Id), closeDate:component.get('v.closeDate') });action.setCallback(this,function (res) {component.set('v.isWorking',false);if (res.getState() ==='SUCCESS') {//Show a toast for the end userlet toastEvent =$A.get('e.force:showToast'); toastEvent.setParams({ title:'Success', type:'success', message:'Action Executed Successfully' }).fire(); component.getEvent('onsuccess').setParams({ action:'ActionExecuted' }).fire();//Close the modalcomponent.find('overlayLib').notifyClose(); } elseif (res.getState() ==='ERROR') {console.log(res.getError()); } });$A.enqueueAction(action); },handleCancel:function (component, event, helper) { component.getEvent('oncancel').setParams({ action:'ActionCancelled' }).fire();component.find('overlayLib').notifyClose(); }});
Apex Controller
The Aura component is ready, let's go ahead and implement the Apex controller. In our example, the job of the controller is straightforward; update the close date of the selected records.
public with sharing classMoveCloseDateController {@AuraEnabledpublicstaticbooleanmoveCloseDate(List<Id> idList,Date closeDate) {List<Opportunity> oppList =newList<Opportunity>();for (Id oppId : idList) {oppList.add(newOpportunity(Id = oppId, CloseDate = closeDate)); }update oppList;returntrue; }}
Action Configuration
Our Aura component and the Apex class are ready for use. Let's go ahead and configure the grid action as below:
LWC is also an option to implement a custom action. GridMate provides an Aura wrapper component to launch any LWC component. Below is the LWC component to update the close date same as the aura component above.