Getting Started with Salesforce Quick Action APIs – Part 2 (Automatically populate fields with custom data values)
This is the 2nd post on Salesforce Quick Action APIs - Part 2. For
Part 1 Please refer to this link Getting Started with Quick Action APIs – Part 1
Note: For Quick Action APIs to work the requested component should be
present on the record current screen from where this action will invoke
else system will through error ☹️
Below is simple Lightning Aura Component - Screen and
ControllerJS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<aura:component controller="QuickActionAPIScreenController" implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes,force:lightningQuickAction" access="global" > | |
<!-- Attribute defination --> | |
<lightning:quickActionAPI aura:id="quickActionAPI" /> | |
<!-- Screen defination --> | |
<div> | |
<!- Add required screen components here..... --> | |
</div> | |
<br/> | |
<div> | |
<lightning:button label="Submit Quote" onclick="{!c.callCaseCloseAction}"/> | |
</div> | |
</aura:component> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
({ | |
callCaseCloseAction : function( component, event, helper ) { | |
var actionAPI = component.find("quickActionAPI"); | |
var fields = { | |
Status : {value : 'Closed'}, | |
Subject : { value : 'Case Ticket Resolved and Closed' }, | |
}; | |
var args = {actionName : "CloseCase", | |
entityName : "Case", | |
targetFields : fields }; | |
actionAPI.setActionFieldValues(args).then(function() { | |
// Call this if you donot want any other User interaction. This will automatically Submit the action. | |
actionAPI.invokeAction(args); | |
}).catch(function(e) { | |
console.log('Error upon calling Email Action: ', JSON.stringify(e)); | |
}); | |
}, | |
}) |
The key items are:
- lightning:quickActionAPI - Used for including Quick Action API in a component
- setActionFieldValues - Promise function used for calling and setting default values. Here for setting values the syntax will be in this formate- field API name with a JSON object with the key will be "Value" and value will be either String or Array separated by a colon ":"
Comments
Post a Comment