Snippets Collections
import { LightningElement, wire, api } from "lwc";

//1. import the methods getRecord and getFieldValue
import { getRecord, getFieldValue } from "lightning/uiRecordApi";

//2. Import reference to the object and the fields
import NAME_FIELD from "@salesforce/schema/Account.Name";
import RATING_FIELD from "@salesforce/schema/Account.Rating";
import INDUSTRY_FIELD from "@salesforce/schema/Account.Industry";

const fields = [NAME_FIELD, RATING_FIELD, INDUSTRY_FIELD];
export default class ExploreGetRecord extends LightningElement {
  @api
  recordId;

  //3. Wire the output of the out of the box method getRecord to the property account
  @wire(getRecord, {
    recordId: "$recordId",
    fields
  })
  account;

  renderedCallback() {
    console.log(this.account.data);
  }
  
  //4. Fetch the field values from the record
  get name() {
    return getFieldValue(this.account.data, NAME_FIELD);
  }

  get rating() {
    return getFieldValue(this.account.data, RATING_FIELD);
  }

  get industry() {
    return getFieldValue(this.account.data, INDUSTRY_FIELD);
  }
}

showNotification(title, msg, variant) {
  const evt = new ShowToastEvent({
    title: title,
    message: msg,
    variant: variant
  })
  this.dispatchEvent(evt);
}

//to use it, call the method passing parameters like "this.showNotification('Title', 'Message', 'success')""
var faturasFechadas = [
    { 
        "valorFatura": {
            "valor": -1665.46, 
            "moeda": "R$" 
            
        },
        "dataFechamento": "2025-03-26T00:00:00", 
    },
    { 
        "valorFatura": {
            "valor": -1665.46, 
            "moeda": "R$" 
            
        }, 
        "dataFechamento": "2025-03-26T00:00:00"
    }
];
    
var detalhesFatura = {
    "numeroCartao": "xxxxxxxxxxxx1193",
    "detalhesLancamentoParcela": {
        "quantidadeParcelas": 12,
        "numeroParcelaTransacao": 7
        
    },
    "dataVencimentoFatura": "2025-03-01T00:00:00"
}

var result = faturasFechadas.map(function(el) {
    var o = Object.assign({}, el);
    o.detalhesFatura = detalhesFatura;
    return o;
});

console.log(JSON.stringify(result));
@wire(callout2Apex,{id: this.recordId})
faturaAbertaWired({ error, data }) {
  if (data) {
    this.arr = JSON.parse(data).keyFromJSON;
    this.loaded = true;
  } else if (error) {
    this.loaded = false;
  };
}
star

Fri Jul 01 2022 15:12:47 GMT+0000 (UTC) https://blog.salesforcecasts.com/how-to-use-getrecord-in-lwc/

#javascript #lwc
star

Fri Jul 01 2022 14:41:53 GMT+0000 (UTC)

#javascript #lwc

Save snippets that work with our extensions

Available in the Chrome Web Store Get Firefox Add-on Get VS Code extension