正解:D
When building a Lightning Web Component (LWC) to collect and manage data, developers must ensure compliance with Salesforce's security model, including field-level security (FLS) and object-level security (OLS). To meet the requirement of respecting security controls, lightning-input-field is the correct choice.
Why lightning-input-field?
* Field-Level Security (FLS):lightning-input-field respects the user's field-level security settings. This means users can only view or edit fields that they have permissions for, ensuring compliance with the organization's security model.
* Object-Level Security (OLS):It respects object-level security, ensuring users cannot access objects they are restricted from accessing.
* Simplified Development:It is part of the Lightning Data Service (LDS), which eliminates the need to write custom Apex or SOQL queries for CRUD operations, reducing the potential for security gaps.
* Dynamic Rendering:Since the component dynamically renders fields based on the user's permissions, developers can share the component across various user groups without additional customization.
* Declarative Syntax:lightning-input-field simplifies form creation in LWC by using declarative syntax to bind to record fields directly.
Example Code Implementation:
<template>
<lightning-record-edit-form
object-api-name="Contact"
record-id={contactId}>
<lightning-messages></lightning-messages>
<lightning-input-field field-name="FirstName"></lightning-input-field>
<lightning-input-field field-name="LastName"></lightning-input-field>
<lightning-input-field field-name="Email"></lightning-input-field>
<lightning-button class="slds-m-top_small" variant="brand" type="submit" name="update" label="Save"><
/lightning-button>
</lightning-record-edit-form>
</template>
References:
* LWC Documentation for lightning-input-field
* Field-Level Security and Object-Level Security
* Best Practices for Lightning Data Service
By using lightning-input-field, the developer ensures adherence to Salesforce's security standards while providing a reusable and secure solution for capturing and displaying Contact information.
最新のコメント (最新のコメントはトップにあります。)
A. aura-input-field
B. force-input-field
C. ui-input-field
D. lightning-input-field ★
正解は D です。
(※選択肢の日本語訳が崩れていますが、「雷=Lightning」「入力=Input」「失敗=Field(フィールドの誤訳)」と読み解くと、lightning-input-field を指しています。)
正解の解説
D. lightning-input-field
この問題の要件は、「Lightning Web コンポーネント (LWC)」 を使用し、かつ 「項目レベルセキュリティ (FLS) を適用する(権限がない項目は表示・編集させない)」 ことです。
機能: lightning-input-field は、lightning-record-edit-form コンポーネント内で使用される入力項目です。
セキュリティ: このコンポーネントは Lightning Data Service (LDS) 上に構築されており、メタデータに基づいて項目レベルセキュリティ (FLS) を自動的に適用します。
ユーザーに「参照権限」がなければ、項目は表示されません。
ユーザーに「編集権限」がなければ、項目は自動的に「読み取り専用」になります。
開発効率: 個別に Apex で権限チェック(isAccessible, isUpdateable)を行う必要がなく、タグを配置するだけでセキュリティ要件を満たすことができます。
不正解の解説
A. aura:inputField (オーラ入力フィールド)
これは Aura コンポーネント 用のタグです。LWC では使用できません。
B. force:inputField (Force入力フィールド)
これも Aura コンポーネント 用のタグであり、現在は非推奨に近い扱いです。LWC では使用できません。
C. ui:inputField (UI入力フィールド)
これも古い Aura コンポーネント 用のライブラリです。
💡 学習のポイント
「LWC で、項目のアクセス権(セキュリティ)を自動的に守ってフォームを作りたい」 と言われたら:
lightning-record-form: 最も簡単。レイアウトごとドーンと表示。
lightning-record-edit-form + lightning-input-field: レイアウトをカスタマイズしたい場合(今回の正解)。
この組み合わせを覚えておきましょう。...