I am new to salesforce and javascript. I am passing an object from parent LWC to child LWC. but some fields in the object are empty or null. Since I am directly accessing them in the child component html, it is throwing errors. what is the best way to do error handling here? should copy the object into another object and check if each field has data and assign it to @api variables? or is there better way?
here is my code: Apex class
@AuraEnabled(cacheable = true)
public static pba__Request__c getTransactionDetails(String recordId){
Trans transDetails = [SELECT Id, Name, loanNum, lenderName
FROM Trans WHERE pba__Contact__c =: recordId limit 1];
return transDetails ;
}
parent js file
@wire(getTransactionDetails, {
recordId: '$recordId'
})
trans({error,data}){
if(data){
console.log(data);
this.bTrans = data;
console.log('btrans', this.bTrans);
}
if(error){
console.log(error)};
};
parent html
<c-mortgage-runway-panel buy-transaction={bTrans}> </c-mortgage-runway-panel>
child js file
export default class MortgageRunwayPanel extends LightningElement {
@api recordId;
@api buyTransaction;
child html
<lightning-input label="Loan Number" class="validate" required={isRequired} value={buyTransaction.LoanNumber_rh__c} onchange={handleLoanNumChange} pattern="[0-9]{10}$" message-when-pattern-mismatch="Please Enter valid 10 digit loan number" read-only={readOnly}> </lightning-input>
when i am recieving data from Parent, the object its self is not null but the loan number is null. How should i handle this? Because I have more than 20 fields that can be empty.