When you click your custom button, the context is passed in the URL as a variable named inContextOfRef
and the value is a base64-encoded string. You can get this value from the URL and decode it in your component. For LWC, you could do something like this:
import { LightningElement } from 'lwc';
export default class MyCoolLWC extends LightningElement {
// this variable will contain the parent record Id
recordId;
// this executes when your LWC is loaded
connectedCallback() {
const params = new Proxy(new URLSearchParams(window.location.search), {
get: (searchParams, prop) => searchParams.get(prop)
});
let inContextOfRef = params.inContextOfRef;
if (inContextOfRef.startsWith("1\.")) { inContextOfRef = inContextOfRef.substring(2); }
var addressableContext = JSON.parse(window.atob(inContextOfRef));
this.recordId = addressableContext.attributes.recordId;
}
}