You need to sign in to do that
Don't have an account?
Poorna Developer
Remove lookup field from the list in lwc
Hi Everyone,
I have created a lwc with my custom object name Loan__c and Standard object Contact. Both have look-up relation. When I choose contact name from the list it will the show related loan details in the Loan__c.
Once I remove the contact from the field I need to remove Loan data from Loan look-up also.
Is any possible to remove the loan when the contact removed.
Code:
import { LightningElement,track,wire,api } from 'lwc';
import getDetails from '@salesforce/apex/LoanController.getDetails';
import { getRecord } from 'lightning/uiRecordApi';
export default class TransactionDetails extends LightningElement {
@api accountId;
@track display=true;
@track cl='true';
@track aId='true';
@track cId='true';
@track acId='true';
@track cnId='true';
@track cloans= '';
@track selectedLoanId;
@track handleRemovePill;
@track contactname;
@track accountname;
@track _recordId;
@track transaction;
@track loans;
hasRendered=false;
ContactoptionList=[];
isClicked=false;
connectedCallback()
{
this.getLabelDetails();
}
@api
get recordId(){
return this._recordId;
}
set recordId(val){
this._recordId = val;
}
selectedContact(event)
{
debugger;
if(this.isClicked){
this.cloans= ''; // display all the loans
this.aId=true;
this.isClicked=false;
this.contactId='';
if(this.contactId=='' && this.selectedLoanId!='')
{
this.cloans='';
this.selectedLoanId=''; //Clear loan from list
console.log('ok'+this.selectedLoanId);
}
}
else{
this.contactId = event.detail.selectedId;
this.cloans = 'Contact__c=\''+this.contactId+'\'';
this.aId=false;
this.isClicked=true;
}
}
I have created a lwc with my custom object name Loan__c and Standard object Contact. Both have look-up relation. When I choose contact name from the list it will the show related loan details in the Loan__c.
Once I remove the contact from the field I need to remove Loan data from Loan look-up also.
Is any possible to remove the loan when the contact removed.
Code:
import { LightningElement,track,wire,api } from 'lwc';
import getDetails from '@salesforce/apex/LoanController.getDetails';
import { getRecord } from 'lightning/uiRecordApi';
export default class TransactionDetails extends LightningElement {
@api accountId;
@track display=true;
@track cl='true';
@track aId='true';
@track cId='true';
@track acId='true';
@track cnId='true';
@track cloans= '';
@track selectedLoanId;
@track handleRemovePill;
@track contactname;
@track accountname;
@track _recordId;
@track transaction;
@track loans;
hasRendered=false;
ContactoptionList=[];
isClicked=false;
connectedCallback()
{
this.getLabelDetails();
}
@api
get recordId(){
return this._recordId;
}
set recordId(val){
this._recordId = val;
}
selectedContact(event)
{
debugger;
if(this.isClicked){
this.cloans= ''; // display all the loans
this.aId=true;
this.isClicked=false;
this.contactId='';
if(this.contactId=='' && this.selectedLoanId!='')
{
this.cloans='';
this.selectedLoanId=''; //Clear loan from list
console.log('ok'+this.selectedLoanId);
}
}
else{
this.contactId = event.detail.selectedId;
this.cloans = 'Contact__c=\''+this.contactId+'\'';
this.aId=false;
this.isClicked=true;
}
}
for this you can create an onchange event on the contact field and check if the contact field is empty or not if empty then you can also provide a blank in the lead lookup field.
for eg: you can check that according to your fields.
If you find your Solution then mark this as the best answer.
Thanks and Regards,
Suraj Tripathi.