2

So we have this Aura component that we are trying to convert to LWC. We have less than 10 small components, so we want to standardize to LWC before it grows big.

but we have one Aura component that is utilizing force:recordData's recordUpdated event that does certain things (i.e. show a tipbox about the next step and whatnot) when a field is updated. As per Salesofrce doc, the LWC counterpart of force:recordData is some kind of wire service - which could be the getRecordUi which returns Record UI object, but it does not have the needed recordUpdated event. The component seats in the Lightning layout, which runs perfectly - i.e. the event is fired when a record is updated using standard page layout.

Do we hit a brick wall here?

The code may not be relevant but I am including those

Component

<aura:component implements="flexipage:availableForAllPageTypes,force:hasRecordId">

    <force:recordData aura:id="forceRecord" 
                      recordId="{!v.recordId}" 
                      layoutType="FULL" 
                      recordUpdated="{!c.recordUpdated}" />

</aura:component>

Controller

recordUpdated: function(cmp,event,helper) {
    var params = event.getParams();

    if(params.changeType === "CHANGED") {
        var changedFields = params.changedFields;
        if (changedFields['Loan_Type__c'].value = 'Auto Loan') {
            //remind user not to forget chattel details, car details, etc.
        }
    }
}

2 Answers 2

2

There's no need for such an event, because you can write a wire handler:

@wire(getRecord, { recordId: '$recordId' })
  someRecordWireHandler({data,error}) {
    if(data) {
      if(this.record) {
        // We're getting an update //
        // We can compare deltas to figure out what changed //
      } else {
        // This is the first time we got data //
      }
      this.record = data;
    }
    if(error) {
      // Handle an error here //
    }
  }

I realize this isn't as nice as recordUpdated, necessarily, but it should probably work for whatever it is you're trying to do.

0

Call you apex method from uiRecordApi wire service using connectedCallback(). Ensure the apex class method should not be annotated with (cacheable = true)

import getLoanDetails from '@salesforce/apex/LoanCtrl.getLoanDetails';
import { getRecord } from 'lightning/uiRecordApi';

@wire(getRecord, { recordId: '$recordId', fields: 'Loan__c.Name' })
wiredGetRecord(value) {
    const { data, error } = value;
    if (data) {
        this.connectedCallback();
    }else if(error) {}
}

async connectedCallback(){
    getLoanDetails({ recId: this.recordId }).then(result =>{
        if(result){
            //remind user not to forget chattel details, car details, etc.
        }
    }).catch(error => {});
}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .