简体   繁体   English

Lightning-record-view 表单不显示具有从顶点 class 获取的 id 的记录。 Salesforce LWC,Apex

[英]Lightning-record-view form is not displaying the record with the id that is fetch from an apex class. Salesforce LWC,Apex

I have a record view for which the id is from apex class and then wired it and assigned to a variable, but the record is not displaying.我有一个记录视图,其 id 来自顶点 class,然后将其连接并分配给一个变量,但记录未显示。 below is my code.下面是我的代码。

apex class to get the record id of the record owned by the user apex class 获取用户拥有的记录的记录id

@AuraEnabled(cacheable=true)
public static Wallet__c getWalletInfo(){
    String userId = UserInfo.getUserId();
    return [SELECT Id From Wallet__c WHERE OwnerId =: userID LIMIT 1];
}

.js class - assigned the data to getId .js class - 将数据分配给 getId

import getWalletInfo from '@salesforce/apex/CustomWalletHandler.getWalletInfo';
import wallet from '@salesforce/schema/Wallet__c';
import walletName from '@salesforce/schema/Wallet__c.Name';
import walletBalance from '@salesforce/schema/Wallet__c.balance__c';
import walletFrom from '@salesforce/schema/Wallet__c.added_from__c';


export default class CustomWallet extends LightningElement {

objectName = wallet;
name = walletName;
balance = walletBalance;
from = walletFrom;

getId;
isUser = true;

@wire (getWalletInfo,{})
walletData({error, data}){ //data is record Id
    if(data){
        this.getId = data;
        console.log(this.getId);
        this.isUser = false;
    }else if(error) {
        // error handling
        console.error(error.body.message);
    }
}


}

html - if user has no recordc Create Wallet will display and if user has record only the record will display. html - 如果用户没有记录,将显示创建钱包,如果用户有记录,则仅显示记录。

<template>
<lightning-card>
    <lightning-tabset>
        <template if:true={isUser}>
            <lightning-tab label="Create a Wallet">
                <lightning-record-form
                object-api-name="Wallet__c"
                columns="2"
                layout-type="Full"
                ></lightning-record-form>
            </lightning-tab>
        </template>
        <template if:false={isUser}>
            <lightning-tab label="My Wallet">
                <lightning-record-view-form
                record-id={getId}
                object-api-name={objectName}>
                <div class="slds-box">
                    <lightning-output-field field-name={name}>
                    </lightning-output-field>
                    <lightning-output-field field-name={balance}>
                    </lightning-output-field>
                    <lightning-output-field field-name={from}>
                    </lightning-output-field>
                </div>
            </lightning-record-view-form>
            </lightning-tab>
        </template>
    </lightning-tabset>
</lightning-card>

这是输出

I think you overcomplicated it a bit.我认为你有点过于复杂了。 What do you get when you put simpler references to object & fields?当您对 object 和字段进行更简单的引用时,您会得到什么?

<lightning-record-view-form
    record-id={getId}
     object-api-name="Wallet__c">
     <div class="slds-box">
         <lightning-output-field field-name="Name"></lightning-output-field>
         <lightning-output-field field-name="Balance__c"></lightning-output-field>
         <lightning-output-field field-name="Added_From__c"></lightning-output-field>
     </div>
</lightning-record-view-form>

And your apex method is returning whole Wallet__c object, not just the Id.而且您的顶点方法返回整个Wallet__c object,而不仅仅是 Id。 With just 1 field populated but still.仅填充了 1 个字段,但仍然存在。 You can tell by seeing curly braces in your console.log's output.您可以通过在 console.log 的 output 中看到花括号来判断。 So you need either this.getId = data.Id;所以你需要this.getId = data.Id; in JS or record-id={getId.Id} in HTML.在 JS 或 HTML 中的record-id={getId.Id}中。 Or make Apex return just an Id variable (and null if no results found I guess?)或者让 Apex 只返回一个 Id 变量(如果我猜没有找到结果,还有 null?)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Salesforce Apex 未更新记录 - Salesforce Apex not updating record LWC,使用电线和 Apex 从 JavaScript 将记录设置到数据库 soql,错误 - LWC, set record to database soql from JavaScript with wire and Apex, error 在 Salesforce 中从 Apex 抛出的 LWC 中捕获异常 - Catch exception in LWC thrown from Apex in Salesforce 有没有办法从闪电 Web 组件(LWC)中的 JS 将多个(和不同的)参数传递给 Apex Controller class? - Is there a way to pass multiple (and different) parameters to an Apex Controller class from JS in Lightning Web Components (LWC)? 使用Salesforce Apex查找记录并从字段中提取数据 - Using Salesforce Apex to find a record and pull data from a field 文件从 Salesforce LWC(无顶点)上传到 Amazon S3 - File upload to Amazon S3 from Salesforce LWC (without apex) Salesforce 使用顶点更新元数据记录 - Salesforce updating metadata record using apex 如何获取指定自定义object记录表单视觉强制页面的ID到顶点class? - How to get the ID for the specified custom object record form visual force page to apex class? Salesforce LWC - 多个 Apex 标注必须失败 - Salesforce LWC - Multiple Apex Callout Imperatively Fails Salesforce:如果记录有一个标记为false的复选框字段,如何防止记录的&#39;upsert&#39;(从顶点作业执行)? - Salesforce : How to prevent 'upsert' (executed from an apex Job) of a record, if the record has a checkbox field which is marked false?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM