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
Moon KnightMoon Knight 

Insert record in Contact Object using LWC

 Need urgent help for this  Question related to LWC.--

 Make two address fields on CONTACT Object , correspondence address and permanent address.
                   We have to fill both the fields with different addresses, if anyone of them is empty then generate message, 
                  and if the checkbox is selected then both the addresses should be same. I Have to do this with LWC

// i have created 2 custom field on contact and 1 checkbox field as well.


..only below field requried in LWC page according to my question's requirement-- .

Last Name = 

Email = 

correspondence address = 

checkbox = [true,false]

permanent address = 


//  can anyone help me ,  I will be really greatful :-)
// make this simple and easy as much you can,but i need this urgently,plese
 
VinayVinay (Salesforce Developers) 
Hi Moon,

Check below examples for inserting record in Contact Object using LWC

https://www.w3web.net/creating-record-in-contact-object-and-redirecting-in-lwc/
https://developer.salesforce.com/forums/?id=9062I000000XsulQAC

Please mark as Best Answer if above information was helpful.

Thanks,
Moon KnightMoon Knight

i already saw that examples, that was not helpful,because in my question i have to apply validation conditions and also i have checkbox field.
can anyone write or send me full code of html and js for this question

brianna jadinbrianna jadin
The apex method requires a Contact as input parameter, but you're passing an object with these four properties that are not Contact's fields:
FNAME
LNAME
Phone
EMAIL
TUSHAR_MATHURTUSHAR_MATHUR
Hi Moon Knight 
Please refer to below code and make improvements according to yourself :

<!-- HTML Start -->
<lightning-record-edit-form
    object-api-name={objectApiName}
    record-id={recordId}
>
<lightning-input-field field-name={lastnameField}></lightning-input-field>
<lightning-input-field field-name={emailField}></lightning-input-field>
<lightning-input-field field-name={correspondenceAddField} value={cAdd} onchange={handleCAdd}></lightning-input-field>
<lightning-input-field field-name={checkboxField} onchange={handleCheckbox}></lightning-input-field>
<lightning-input-field field-name={permanentAddField} value={pAdd} disabled={sameAdd}></lightning-input-field>
    <div class="slds-var-m-top_medium">
        <lightning-button variant="brand" type="submit" label="Save">
        </lightning-button>
    </div>
</lightning-record-edit-form>
<!-- HTML END-->

// JS Start
import { LightningElement, api , track} from 'lwc';

export default class yourComponentName extends LightningElement {

    // Flexipage provides recordId and objectApiName
    @api recordId;
    @track objectApiName = 'Put Your Object APi Name';
@track lastnameField = 'Put Your lastnameField API Name';
@track emailField = 'Put Your Email API Name';
@track correspondenceAddField = 'Put Your correspondenceAddField API Name';
@track checkboxField = 'Put Your checkboxField API Name';
@track permanentAddField = 'Put Your permanentAddField API Name';
@track cAdd;
@track pAdd;
@track sameAdd;

handleCAdd(event){
this.cAdd = event.target.value;
}
handleCheckbox(event){
if(event.target.value == true){
this.sameAdd = true;
this.pAdd = this.cAdd;
}
else{
this.sameAdd = false;
}
}

}

// JS End

If this helps mark this answer as the best.

Thanks & Regards
Tushar Mathur