Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
// cmp
<aura:component access="global" implements="lightning:actionOverride,force:hasRecordId,force:hasSObjectName,lightning:isUrlAddressable"
description="proof of concept cmp">
<aura:attribute name="contextId" type="String"/>
<aura:attribute name="windowURL" type="String"/>
<aura:handler name="init" value="this" action="{!c.init}"/>
<lightning:card title="Details">
<div class="slds-p-around_medium">
<p>RecordId (should be empty for new action): <b>{!v.recordId}</b></p>
<p>Name of object to be created or edited: <b>{!v.sObjectName}</b></p>
<p>sObject from which action was invoked: <b>{!v.contextId}</b></p>
<p>Current User Id: <b>{!$SObjectType.CurrentUser.Id}</b></p>
init : function(component, event, helper) {
var pageRef = component.get("v.pageReference");
component.set("v.windowURL", window.location.href);
if (pageRef && pageRef.state && pageRef.state.inContextOfRef) {
var state = pageRef.state; // state holds any query params
var base64Context = state.inContextOfRef;
// For some reason, the string starts with "1.", if somebody knows why,
// this solution could be better generalized.
if (base64Context.startsWith("1\.")) {
base64Context = base64Context.substring(2);
var addressableContext = JSON.parse(window.atob(base64Context));
component.set("v.contextId", addressableContext.attributes.recordId);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment