Skip to content

Instantly share code, notes, and snippets.

@Szandor72
Created March 7, 2019 10:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Szandor72/fddc8d65cc4feaa170e13d69c5aab777 to your computer and use it in GitHub Desktop.
Save Szandor72/fddc8d65cc4feaa170e13d69c5aab777 to your computer and use it in GitHub Desktop.
// 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