How to use the lwc.wire function in lwc

To help you get started, we’ve selected a few lwc examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github FabienHuot / KnowledgeSearch / force-app / main / default / lwc / knowledgeSearch / knowledgeSearch.js View on Github external
@wire(KnowledgeRecordTypes)
    wiredRecordTypes({error, data}) {
        if (data) {
            this.rtList = data;
            console.log('data', data);
            this.error = undefined;
        }
        if (error) {
            this.error = error;
            console.log('data error', error);
            this.rtList = undefined;
        }
    };
    
    @wire(KnowledgeArticles, {input : '$article', cat : '$rt'})
    wiredArticles({error, data}) {
        if (data) {

            this.articleList = [];
            for (let article of data) {
                let myArticle = {};
                myArticle.data = article;

                // Get article url
                this.KnowledgePageRef = {
                    type: "standard__recordPage",
                    attributes: {
                        "recordId": article.Id,
                        "objectApiName": "Knowledge__kav",
                        "actionName": "view"
                    }
github maaaaarco / Salesforce-Custom-Path-Assistant-LWC / force-app / main / default / lwc / pathAssistant / pathAssistant.js View on Github external
);

        this._scenarios.push(
            new ChangeClosedScenario(
                new ScenarioLayout(
                    'Select Closed {0}',
                    'Change Closed {0}',
                    token
                )
            )
        );
    }

    /* ========== WIRED METHODS ========== */

    @wire(getRecordUi, {
        recordIds: '$recordId',
        layoutTypes: 'Full',
        modes: 'View'
    })
    wiredRecordUI({ error, data }) {
        if (error) {
            this.errorMsg = error.body.message;
        }

        if (data && data.records[this.recordId]) {
            // set the record
            this.record = data.records[this.recordId];

            // set the object info
            this.objectInfo = data.objectInfos[this.objectApiName];
github tsalb / lwc-utils / force-app / main / default / lwc / lwcContactDatatable / lwcContactDatatable.js View on Github external
{type: 'button', initialWidth: 155,
    typeAttributes: {label: 'Update Address', name: 'update_address', title: 'Click to open modal to update Mailing Address'}},
];

export default class LwcContactDatatable extends LightningElement {
  @api
  get recordId() {
    return this._recordId;
  }
  set recordId(value) {
    this._accountId = value;
    this._recordId = value;
  }
  @track columns = TABLE_COLUMNS;

  @wire(CurrentPageReference)pageRef;

  @wire(wireContactsByAccountId, { accountId: '$_accountId' })
  contacts;

  // private
  _accountId; // app flexipages
  _recordId;  // record flexipage

  connectedCallback() {
    registerListener('accountSelected', this.handleAccountSelected, this);
    registerListener('forceRefreshView', this.reloadTable, this);
    registerListener('clearTable', this.handleClearTable, this);
  }

  disconnectedCallback() {
    unregisterAllListeners(this);
github barryhughes1 / pluralSightQuestionnaires_LWCs / 04. Completed Solution / main / questionnaires / lwc / questionnaireLwc / questionnaireLwc.js View on Github external
variant: 'success',
                    }),
                );
            })
            .catch(error => {
                this.dispatchEvent(
                    new ShowToastEvent({
                        title: 'Error creating record',
                        message: error.body.message,
                        variant: 'error',
                    }),
                );
            });
    }

    @wire(getRecord, { recordId: '$questionnaireReturnedId', fields: FIELDS })
    questionnaireRecord(result) {
        if (result.data) {
            console.log('Questionnaire Return LDS retrieved');
            this.questionnaireReturned = result.data;
            this.termsConditions = this.questionnaireReturned.fields.Terms_and_Conditions__c.value;
            this.questionnaireSubmitted = this.questionnaireReturned.fields.Submitted__c.value;
            this.error = undefined;
            this.questionnaireReturnedReady = true;
        } else if (!this.questionnaireReturnedId) {
            console.log('No Questionnaire Return ID');
            this.questionnaireReturnedReady = true;
        } else if (result.error) {
            console.log('ERROR');
            this.error = result.error;
            this.questionnaireReturned = undefined;
        }
github lucianostraga / userInteractions-platformEvents-lwc / force-app / main / default / lwc / interactionNavigationViewer / interactionNavigationViewer.js View on Github external
console.log(this.recordId);

            if(this.recordId){
                console.log('aca');
                this.getSessionClicks();
            }else{
                console.log('ac2');
                this.getAllClicks();
                
            }

            
        }
    }

    @wire(getDevicesWithScreens)
    wiredDevices({ error, data }) {
        if (data) {
            data.forEach(device => {
                this.devicesOptions.push( {label : device.Name, value : device.Id} );
                this.devicesJson[device.Id] = device;
            });
        } else if (error) {
            console.error(error);
        }
    }


    getAllClicks(){
        getUserClicks({urlPath : this.path, width: this.width, height: this.height})
            .then(result => {
                if(result.length > 0 ){
github pmdartus / rcast / src / client / modules / component / playerCondensed / playerCondensed.js View on Github external
export default class PlayerCondensed extends LightningElement {
    episodeId = null;

    @track episode = null;
    @track podcast = null;

    @track isPlaying = false;
    @track progress = 0;

    _audioContext;
    _audioEl;

    _duration = 0;

    @wire(connectStore, { store })
    storeChange({ player, episodes, podcasts }) {
        this.isPlaying = player.isPlaying;

        const episodeId = player.episode;

        if (!episodes[episodeId]) {
            return;
        }

        const episode = episodes[episodeId].data;
        const podcast = podcasts[episode.podcastId].data;

        if (this.episodeId !== episodeId) {
            this.episodeId = episodeId;
            this.episode = episode;
            this.podcast = podcast;
github tsalb / lwc-utils / force-app / main / default / lwc / lwcAccountSelector / lwcAccountSelector.js View on Github external
import { LightningElement, track, wire } from 'lwc';
import { CurrentPageReference } from 'lightning/navigation';
import { ShowToastEvent } from 'lightning/platformShowToastEvent';
import { fireEvent } from 'c/pubsub';
import getAccountOptionsCache from '@salesforce/apex/DataServiceCtrl.getAccountOptionsCache';

export default class LwcAccountSelector extends LightningElement {
  @track topAccounts;

  @wire(CurrentPageReference) pageRef;

  @wire(getAccountOptionsCache)
  wiredTopAccounts({ error, data }) {
    if (data) {
      this.topAccounts = data.items;
    } else if (error) {
      this.dispatchEvent(
        new ShowToastEvent({
          message: String(error),
          variant: "error",
        })
      );
    }
  }

  handleAccountOptionSelected(event) {
github salesforce / lwc / packages / lwc-wire-service / playground / x / singleWire / singleWire.js View on Github external
import { LightningElement, api, wire } from 'lwc';
import { getTodo } from 'x/todoApi';

export default class SingleWire extends LightningElement {
    @api todoId;

    @wire(getTodo, { id: '$todoId' })
    todo;

    get error() {
        return 'Error loading data: ' + this.todo.error.message;
    }
}
github dreamhouseapp / dreamhouse-lwc / force-app / main / default / lwc / propertyMap / propertyMap.js View on Github external
'Property__c.Location__Latitude__s',
    'Property__c.Location__Longitude__s'
];

export default class PropertyMap extends LightningElement {
    @api recordId;

    @track address;

    @track zoomLevel = 14;

    @track markers = [];

    @track error;

    @wire(CurrentPageReference) pageRef;

    @wire(getRecord, { recordId: '$recordId', fields })
    wiredRecord({ error, data }) {
        if (data) {
            this.error = undefined;
            const property = data.fields;
            this.address = `${property.Address__c.value}, ${property.City__c.value}`;
            this.markers = [
                {
                    location: {
                        Latitude: property.Location__Latitude__s.value,
                        Longitude: property.Location__Longitude__s.value
                    },
                    title: `${property.Address__c.value}`
                }
            ];
github salesforce / lwc / packages / lwc-wire-service / playground / x / multipleWires / multipleWires.js View on Github external
@api
    get todoId() {
        return this.idA;
    }

    set todoId(value) {
        value = Number.parseInt(value, 10);
        if (!Number.isInteger(value)) {
            this.idA = this.idB = undefined;
            return;
        }
        this.idA = value;
        this.idB = value + 1;
    }

    @wire(getTodo, { id: '$idA' })
    todoA;

    @wire(getTodo, { id: '$idB' })
    todoB;

    get hasError() {
        return this.todoA.error || this.todoB.error;
    }

    get error() {
        return '' +
            (this.todoA.error ?  this.todoA.error.message : '') +
            ' / ' +
            (this.todoB.error ?  this.todoB.error.message : '');
    }
}