正解: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-fieldis 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.