lwc#wire JavaScript Examples

The following examples show how to use lwc#wire. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: drawAnnotation.js    From DrawAnnotations with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
// keep this unassigned as it gets assigned dynamically
    @wire(getRecord, { recordId: "$recordId", fields: "$fieldsFormatted" })
    wiredRecord({ error, data }) {
        if (error) {
            this.logAndDisplayError("Error loading wiredRecord of getRecord", error);
        } else { // if (data) {
            this._record = data;
            if (this.autoLoad) {
                // map the record value into the canvas value
                this.getCanvas().currentCanvasValue = this.currentRecordValue;
                this.loadBackgroundImage(); // overwrite the loaded value
            }
        }
    }
Example #2
Source File: tableauViz.js    From tableau-viz-lwc with MIT License 6 votes vote down vote up
@wire(getRecord, {
        recordId: '$recordId',
        fields: '$sfAdvancedFilter'
    })
    getRecord({ error, data }) {
        if (data) {
            this.advancedFilterValue = getFieldValue(
                data,
                this.sfAdvancedFilter
            );
            if (this.advancedFilterValue === undefined) {
                this.errorMessage = `Failed to retrieve value for field ${this.sfAdvancedFilter}`;
            } else {
                this.renderViz();
            }
        } else if (error) {
            this.errorMessage = `Failed to retrieve record data: ${reduceErrors(
                error
            )}`;
        }
    }
Example #3
Source File: filesRelatedList.js    From lwc-files-list with MIT License 6 votes vote down vote up
//}}}

  @wire(getRelatedFiles, { recordId: "$recordId" })
  getFilesList(filesList) {
    //{{{
    this._filesList = filesList;
    const { error, data } = filesList;
    if (!error && data) {
      this.files = data;
      console.log("files found " + JSON.stringify(this.files));
    }
  }
Example #4
Source File: sobjectsPanel.js    From lwc-soql-builder with MIT License 6 votes vote down vote up
@wire(connectStore, { store })
    storeChange({ sobjects }) {
        if (this._rawSObjects) return;
        this.isLoading = sobjects.isFetching;
        if (sobjects.data) {
            this._rawSObjects = sobjects.data.sobjects.map(sobject => {
                return {
                    ...sobject,
                    itemLabel: `${sobject.name} / ${sobject.label}`
                };
            });
            this.sobjects = this._rawSObjects;
        } else if (sobjects.error) {
            console.error(sobjects.error);
            showToast({
                message: this.i18n.SOBJECTS_PANEL_FAILED_FETCH_SOBJECTS,
                errors: sobjects.error
            });
            store.dispatch(clearSObjectsError());
        }
    }
Example #5
Source File: relationshipsTree.js    From lwc-soql-builder with MIT License 6 votes vote down vote up
@wire(connectStore, { store })
    storeChange({ sobjects, sobject, ui }) {
        if (!this._sobjectLabelMap && sobjects.data) {
            this._sobjectLabelMap = this._getSObjectLabelMap(sobjects.data);
        }
        const sobjectState = sobject[this.sobject];
        if (!sobjectState) return;
        if (sobjectState.data) {
            this.sobjectMeta = sobjectState.data;
        }

        this._updateRelationships(ui.query);
    }
Example #6
Source File: queryEditorPanel.js    From lwc-soql-builder with MIT License 6 votes vote down vote up
@wire(connectStore, { store })
    storeChange({ sobject, ui }) {
        const { query, soql } = ui;
        if (sobject && query) {
            const sobjectState = sobject[fullApiName(query.sObject)];
            if (sobjectState) {
                this._sobjectMeta = sobjectState.data;
            }
        }
        if (soql !== this.soql) {
            this.soql = soql;
        }
    }
Example #7
Source File: outputPanel.js    From lwc-soql-builder with MIT License 6 votes vote down vote up
@wire(connectStore, { store })
    storeChange({ query, ui }) {
        this.isLoading = query.isFetching;
        if (query.data) {
            if (this.response !== query.data) {
                this.response = query.data;
                this._sObject = ui.query.sObject;
            }
        } else {
            this.response = undefined;
        }
        if (query.error) {
            console.error(query.error);
            showToast({
                message: this.i18n.OUTPUT_PANEL_FAILED_SOQL,
                errors: query.error
            });
            store.dispatch(clearQueryError());
        }
        this.childResponse = ui.childRelationship;
    }
Example #8
Source File: fieldsTree.js    From lwc-soql-builder with MIT License 6 votes vote down vote up
@wire(connectStore, { store })
    storeChange({ sobject, ui }) {
        const sobjectState = sobject[this.sobject];
        if (!sobjectState) return;
        this.isLoading = sobjectState.isFetching;
        if (sobjectState.data) {
            this.sobjectMeta = sobjectState.data;
        }

        this._updateFields(ui.query, ui.sort);
    }
Example #9
Source File: fieldsPanel.js    From lwc-soql-builder with MIT License 6 votes vote down vote up
@wire(connectStore, { store })
    storeChange({ sobjects, sobject, ui }) {
        const { selectedSObject } = ui;
        if (!selectedSObject) return;

        const fullSObjectName = fullApiName(selectedSObject);
        if (
            sobjects &&
            !sobjects.data.sobjects.find(o => o.name === fullSObjectName)
        ) {
            return;
        }
        if (fullSObjectName !== this._selectedSObject) {
            this._selectedSObject = fullSObjectName;
            store.dispatch(describeSObjectIfNeeded(this._selectedSObject));
        }

        const sobjectState = sobject[this._selectedSObject];
        if (!sobjectState) return;
        this.isLoading = sobjectState.isFetching;
        if (sobjectState.data) {
            this.sobjectMeta = sobjectState.data;
        } else if (sobjectState.error) {
            console.error(sobjectState.error);
            showToast({
                message: this.i18n.FIELDS_PANEL_FAILED_DESCRIBE_OBJ,
                errors: sobjectState.error
            });
            store.dispatch(clearSObjectError(this._selectedSObject));
        }
    }
Example #10
Source File: container.js    From lwc-soql-builder with MIT License 6 votes vote down vote up
@wire(connectStore, { store })
    storeChange({ ui }) {
        this.isLoggedIn = ui.isLoggedIn;
        if (ui.selectedSObject) {
            this.selectedSObject = ui.selectedSObject;
        } else {
            this.selectedSObject = null;
        }
    }
Example #11
Source File: videoViewer.js    From VideoViewer with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
// Get a list of attached documents based on recordId.
  // If there are no attachments, and the object type is ContentDocument(File)
  // Change the current video url, else show error
  @wire(getAttachedDocuments, { recordId: "$recordId" })
  getDocuments({ error, data }) {
    this.hasLoadingCompleted = true;
    if (data) {
      if (data.length) {
        this.videoMap = Object.assign({}, data);
        this.currentVideoCount = 0;
        this.totalVideos = data.length;
        this.showNavigation = !!(data.length - 1);
        this.hasNoVideos = false;
      } else {
        this.showNavigation = false;
        if (this.objectApiName === CONTENTDOCUMENT_OBJECT.objectApiName) {
          this.hasNoVideos = false;
          this.currentVideoUrl = this.baseVideoUrl + this.recordId;
        }
      }
    }
    if (error) {
      this.hasError = true;
    }
  }
Example #12
Source File: drawAnnotation.js    From DrawAnnotations with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@wire(getStamps)
    wiredStamps({ error, data }) {
        if (error) {
            this.logAndDisplayError("Error loading wiredRecord of getRecord", error);
        } else { // if (data) {
            this._stamps = data;
            this._stampsAdded = 0;
            this.loadStamps();
        }
    }
Example #13
Source File: filterCriteria.js    From ActivityTimelineLWC with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@wire(getFieldsForObject, { objectApiName: '$childObjectApiName' })
    childObjectFields({ error, data }) {
        if (data) {
            console.log(`Fetched ${this.childObjectApiName}'s object info`);
            this.processFieldResults(data, false);
        }
        if (error) {
            console.log(`Error fetching ${this.childObjectApiName}'s object info... ${JSON.stringify(error)}`);
        }
    }
Example #14
Source File: objectDetailsConfig.js    From AppRecordDetails with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
// Flag to show hide new section in config page

    /* 
    *  Info: This wire mothod is invoking uiApi to get object information
    *  Params: objName-Object name passed from the details page
    *  Result: Get list of fields and set in options in form of label-value pair used in multi picklist
    */
    @wire(getObjectInfo, { objectApiName: '$objName' })
    getObjMetadata( { data }){
        if (data) {
            const items =[];

            for (const field in data.fields) {
                if (data.fields.hasOwnProperty(field)) {
                    let fieldLabel = data.fields[field].label;
                    let fieldAPI = data.fields[field].apiName;
                    //Constructing label value pair for multiselect picklist
                    items.push({label: fieldLabel,
                                value: fieldAPI});
                    
                }
            }
            
            this.options.push(...items);
            
        }
    }
Example #15
Source File: objectDetails.js    From AppRecordDetails with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/* 
    *  Info: This wire mothod is invoking uiApi to get context users information information
    *  Params: configName-Config name of metadata
    *  Params: objName-Object Name string
    *  Result: Check profile name of context user to show hide settings icon
    */
    @wire(getObjectDetailConfigMethod, { configName: '$configName',objName: '$objName' })
    getConfig(result) {
        if (result.data) {
            this.configData = result.data;
            this.error = undefined;
            if(result.data.length == 0){
                this.isFirstLoad = true;
            }
                
        } else if (result.error) {
            this.error = result.error;
            this.configData = undefined;
        }
    }
Example #16
Source File: objectDetails.js    From AppRecordDetails with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/* 
    *  Info: This wire mothod is invoking uiApi to get context users information information
    *  Params: recordId-User id of context user
    *  Params: fields-Profile Name of context user
    *  Result: Check profile name of context user to show hide settings icon
    */
    @wire(getRecord, {
        recordId: USER_ID,
        fields: [PROFILE_NAME]
    })
    wireuser( { error,data }){
        if (data && this.profileNames) {
            let profilelist = this.profileNames.split(',');
            let profName = data.fields.Profile.displayValue

            if(profilelist.includes(profName)){
                this.isConfigVisible = true;
            }
        }else if(error){
            this.error = error;
        }    
    }
Example #17
Source File: timelineItemTask.js    From ActivityTimelineLWC with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@wire(getEmailDetails,{taskId:'$recordId'})
    emailMessage ({ error, data }) {
        if (data) {
            this.assignedToName=data.FromName;
            this.description=data.TextBody;
            this.recordId=data.Id;
            this.activityId=data.ActivityId;
            if(data.ToAddress){
                this.toAddresses=data.ToAddress.split(';');
                this.firstRecipient=this.toAddresses[0];
            }
            if(data.CcAddress){
                this.ccAddresses=data.CcAddress.split(';');
            }
            let emailRelations = data.EmailMessageRelations;
            if(emailRelations && emailRelations.length>=1){
                if(emailRelations[0].Relation){
                    this.whoToName=emailRelations[0].Relation.Name;
                    this.whoId=emailRelations[0].RelationId;
                }
                for(var i=0;i<emailRelations.length;i++){
                    if(emailRelations[i].RelationType == "FromAddress"){
                        if(emailRelations[i].Relation){
                            this.assignedToName=emailRelations[i].RelationId===CURRENT_USER_ID?You:emailRelations[i].Relation.Name;
                            this.ownerId=emailRelations[i].RelationId;
                        }else{
                            this.assignedToName = data.FromName;
                        }
                    }
                }

            }
           
        } 
    }
Example #18
Source File: timelineComposer.js    From ActivityTimelineLWC with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@wire(getObjectInfo, { objectApiName: '$objectApiName' })
    objectInfoResponse({error,data}){
        if(data){
            this.recordIconUrl=data.themeInfo.iconUrl;
            this.recordObjectColor=data.themeInfo.color;
            this.recordNameField = data.nameFields[0];
            
            getObjectName({objectName:this.objectApiName,recordId:this.recordId,nameField:this.recordNameField})
            .then(data =>{
                this.recordName=data;
            }).catch(error =>{
                console.log(JSON.stringify(error));
            });
        }
    }
Example #19
Source File: selectChildObject.js    From ActivityTimelineLWC with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@wire(getObjectInfo, { objectApiName: '$objectApiName' })
    objectInfoResponse({error,data}){
        if(data){
            
            if(data.childRelationships){
                this.childRelationships = new Array();
                for(let i=0;i<data.childRelationships.length;i++){
                    let childObject = data.childRelationships[i];
                    this.childRelationships.push({
                        id:childObject.childObjectApiName+'_'+childObject.relationshipName,
                        apiName:childObject.childObjectApiName,
                        relationshipName:childObject.relationshipName,
                        fieldName:childObject.fieldName
                    });
                }
            }
            
        }
        if(error){
            console.log(JSON.stringify(error,null,4));
        }
        this.isLoading=false;
    }
Example #20
Source File: selectApexRecordProvider.js    From ActivityTimelineLWC with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
// Wire method to function, which accepts the Search String, Dynamic SObject, Record Limit, Search Field  
    @wire(searchForApexClass, { searchString: '$searchString' })
    matchingApexClasses({ error, data }) {
        this.noRecordsFlag = 0;
        if (data) {
            this.records = data;
            this.error = undefined;
            this.noRecordsFlag = this.records.length === 0 ? true : false;
        } else if (error) {
            this.error = error;
            this.records = undefined;
        }
    }
Example #21
Source File: getQuickActionsForObject.js    From ActivityTimelineLWC with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@wire(getObjectInfo, { objectApiName: '$objectApiName' })
    objectInfoResponse({error,data}){
        if(data){
            this.recordIconUrl=data.themeInfo.iconUrl;
            this.recordObjectColor=data.themeInfo.color;
            this.recordNameField = data.nameFields[0];
            
            getObjectName({objectName:this.objectApiName,recordId:this.recordId,nameField:this.recordNameField})
            .then(data =>{
                this.recordName=data;
            }).catch(error =>{
                console.log(JSON.stringify(error));
            });
        }
    }
Example #22
Source File: getObjectNameFromConfig.js    From ActivityTimelineLWC with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@wire(getObjectApiName,{recordId:'$recordId'})
    initializeObjectApiName({ error, data }) {
        if (data) {
            this.objectApiName = data;
            this.error = undefined;
        } else if (error) {
            this.error = error;
            this.objectApiName = undefined;
        }
    }
Example #23
Source File: filterCriteria.js    From ActivityTimelineLWC with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@wire(getFieldsForObject, { objectApiName: '$objectApiName' })
    parentObjectInfo({ error, data }) {
        if (data) {
            console.log(`Fetched ${this.objectApiName}'s object info`);
            this.processFieldResults(data, true);
        }
        if (error) {
            console.log(`Error fetching ${this.objectApiName}'s object info... ${JSON.stringify(error)}`);
        }
    }
Example #24
Source File: selectFieldsForConfig.js    From ActivityTimelineLWC with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@wire(getObjectInfo, { objectApiName: '$childObjectApiName' })
    getFieldNamesForObjectResponse({ error, data }) {
        if (data) {
            this.iconImageUrl = data.themeInfo.iconUrl;
            this.objectColor = data.themeInfo.color;
            let fields = data.fields;
            let fieldResults = [];
            for (let field in fields) {
                if (Object.prototype.hasOwnProperty.call(fields, field)) {
                    if (this.stepName === "Display Fields" || this.stepName === "Title Field") {
                        fieldResults.push({
                            fieldId: fields[field].apiName,
                            label: fields[field].label,
                            apiName: fields[field].apiName,
                            type: fields[field].dataType
                        });
                    }

                    if (this.stepName === "Overdue Field") {
                        if (fields[field].dataType.toUpperCase() === "Boolean".toUpperCase()) {
                            fieldResults.push({
                                fieldId: fields[field].apiName,
                                label: fields[field].label,
                                apiName: fields[field].apiName,
                                type: fields[field].dataType
                            });
                        }
                    }
                    if (this.stepName === "Date Field") {
                        if (fields[field].dataType === "DateTime" || fields[field].dataType === "Date") {
                            fieldResults.push({
                                fieldId: fields[field].apiName,
                                label: fields[field].label,
                                apiName: fields[field].apiName,
                                type: fields[field].dataType
                            });
                        }
                    }

                }
            }
            this.fields = fieldResults;
            this.isLoading = false;
        }
        if (error) {
            console.log(JSON.stringify(error, null, 4));
            this.uiApiNotSupported = true;
            getFieldsForObject({ objectApiName: this.childObjectApiName })
                .then(result => {
                    this.processFieldResults(result);
                })
                .catch(error => {
                    this.error = error;
                });
        }
    }
Example #25
Source File: header.js    From lwc-soql-builder with MIT License 5 votes vote down vote up
@wire(connectStore, { store })
    storeChange({ ui }) {
        this.isLoggedIn = ui.isLoggedIn;
        this._user = ui.user;
        this._apiUsage = ui.apiUsage;
    }
Example #26
Source File: queryListPanel.js    From lwc-soql-builder with MIT License 5 votes vote down vote up
@wire(connectStore, { store })
    storeChange({ ui }) {
        if (ui.recentQueries) {
            this.recentQueries = ui.recentQueries.map((query, index) => {
                return { key: `${index}`, soql: query };
            });
        }
    }
Example #27
Source File: getQuickActionsForObject.js    From ActivityTimelineLWC with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@wire(getCurrentUsername)
    usernameResponse({error,data}){
        if(data){
            this.currentUsername=data;
        }
    }