function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
jishan royjishan roy 

How to update contact record by using lightning input fields in account record page.

This is my code its work on contact record page but not work in account record page please any one can help me.

html:
<template>
    <lightning-card title="Related Fields" custom-icon="custom:icon13">
        <template if:true={record}></template>
    <lightning-record-edit-form
   
        record-id={recordId}
        object-api-name="objectApiName"
       
        onsuccess={handleSuccess} onsubmit ={handleSubmit}>
   
        <lightning-messages> </lightning-messages>
        <lightning-output-field field-name="AccountId">
        </lightning-output-field>
        <lightning-input-field field-name="LastName"> </lightning-input-field>
        <lightning-input-field field-name="FirstName"> </lightning-input-field>
        <lightning-input-field field-name="Phone"> </lightning-input-field>
        <lightning-button
            class="slds-m-top_small"
            variant="brand"
            type="submit"
            name="update"
            label="Update"
        >
        </lightning-button>
    </lightning-record-edit-form>
  </lightning-card>
  </template>

J.S.

import { LightningElement,api,wire,track } from 'lwc';
import getContacts from '@salesforce/apex/contactController.getContacts';
import LAST_NAME_FIELD from '@salesforce/schema/Contact.LastName';
import PHONE_FIELD from '@salesforce/schema/Contact.Phone';
export default class contactAccountInfo extends LightningElement {
  @api recordId;
  @api objectApiName;
  @track contactRecord;
  fields = [LAST_NAME_FIELD, PHONE_FIELD];
  @wire(getContacts, { accId: '$recordId' })
  cons({error,data}){
    console.log('recordId',this.recordId);
    if (data) {
        console.log('>>>data: ' + JSON.stringify(data));
        this.record = data;
        this.error = undefined;
        console.log('recordId',this.record);
    } else if (error) {
        this.error = error;
        this.data = undefined;
    }
}
handleSuccess(event) {
    this.recordId = event.detail.id;
    alert('Id: '+event.detail.id);
}
  }

apex class:

public with sharing class contactController {
    @AuraEnabled(cacheable=true)
    public static List<Contact> getContacts(String accId) {
        return [
            SELECT AccountId, Id, FirstName, LastName, Title, Phone, Email
            FROM Contact
            WHERE AccountId = :accId
             
           ];
       
    }
}


Thanks in advance.
PriyaPriya (Salesforce Developers) 

Hey Jishan,

Kindly refer this document that macthes your requirement :- 

https://developer.salesforce.com/docs/component-library/bundle/lightning-record-edit-form/documentation

If it helps, kindly mark it as the best answer. 

Regards,

Priya Ranjan