Created
March 7, 2019 10:24
-
-
Save Szandor72/fddc8d65cc4feaa170e13d69c5aab777 to your computer and use it in GitHub Desktop.
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
// 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> | |
<p>URL:</p><br/> | |
{!v.windowURL} | |
</div> | |
</lightning:card> | |
</aura:component> | |
//JS | |
({ | |
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