如何在 salesforce 的相关列表中获取父 ID

发布于 2025-01-12 10:37:40 字数 171 浏览 1 评论 0原文

如何在相关列表的自定义按钮单击时获取父 ID。

问题探索:- 当我们打开“帐户详细信息记录”页面并进入相关选项卡时,我们会看到一个联系人列表,并且联系人列表磁贴上有一个新按钮...当我们单击该新按钮时,新记录模式将打开,并带有预设置-其中填充的帐户。

所以,我必须创建一个自定义按钮来完成同样的事情。

How to get parent id on custom button click of the related list.

Question Exploration:- when we open the Account detail record page and go in the related tab we have a contact list there and a new button on the contact list tile...when we click that new button new record modal is open with a pre-populated account in it.

so, I have to create a custom button that does this same thing.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

予囚 2025-01-19 10:37:40

当您单击自定义按钮时,上下文将作为名为 inContextOfRef 的变量在 URL 中传递,并且该值是一个 Base64 编码的字符串。您可以从 URL 获取此值并在组件中对其进行解码。对于 LWC,你可以这样做:

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;
    }
}

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;
    }
}
恏ㄋ傷疤忘ㄋ疼 2025-01-19 10:37:40

这对我有用:

connectedCallback() {
       
        const params = new Proxy(new URLSearchParams(window.location.search), {
            get: (searchParams, prop) => searchParams.get(prop)
        });
        console.log('params...',params);
        console.log('window.location.search',window.location.search);
        let inContextOfRef = params.inContextOfRef;
    
        if (inContextOfRef.startsWith("1\.")) { inContextOfRef = inContextOfRef.substring(2); }
        var addressableContext = JSON.parse(window.atob(inContextOfRef));
        console.log('addressableContext attribute json....',JSON.stringify(addressableContext.attributes));
        

        const params1 = new URLSearchParams(JSON.stringify(addressableContext.attributes));
         this.recordId = params1.get('eid');

        console.log('eid.....',params1.get('eid'));
      
    }

This worked for me:

connectedCallback() {
       
        const params = new Proxy(new URLSearchParams(window.location.search), {
            get: (searchParams, prop) => searchParams.get(prop)
        });
        console.log('params...',params);
        console.log('window.location.search',window.location.search);
        let inContextOfRef = params.inContextOfRef;
    
        if (inContextOfRef.startsWith("1\.")) { inContextOfRef = inContextOfRef.substring(2); }
        var addressableContext = JSON.parse(window.atob(inContextOfRef));
        console.log('addressableContext attribute json....',JSON.stringify(addressableContext.attributes));
        

        const params1 = new URLSearchParams(JSON.stringify(addressableContext.attributes));
         this.recordId = params1.get('eid');

        console.log('eid.....',params1.get('eid'));
      
    }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文