Search In This Blog

2022-12-23

Catch System.LimitException in LWC

System.LimitException cannot catch by [try...catch...] in Apex.

When call Apex method in lwc and LimitException occurred in Apex source, [try...catch...] also not working in js.

But LimitException can be catched by [Promise.catch]

Sample
Promise.all([
    promise1,
    promise2,
    promise3
]).then((values) => {
    console.log(values);
}).catch((error) => {
    // LimitException can be catched here
    console.error(error);
}).finally(() => {
    console.log('Experiment completed');
});

2022-11-30

Custom auto open utility bar without popout button by aura

cmp
<aura:compomemt implements="lightning:utilityItem">
    <!-- define popout to false -->
    <aura:attribute name="supportsPopOut" type="Boolean" default="false" />

    <!-- auto open utility bar when init -->
    <aura:handler name="init" value="{!this}" action="{!c.doInit}"/>

    <!-- use lightning:utilityBarAPI -->
    <lightning:utilityBarAPI aura:id="utilitybar" />

    someting else
</aura:compomemt>

controller.js
doInit: function(component) {
    var utilityApi = component.find("utilitybar");
    utilityApi.getAllUtilityInfo().then(fuction (response) {
        if (typeof response != "undefined") {
            utilityApi.openUtility();
        }
    });
}

Get recordId in LWC

Way 1
In js-meta.xml, set targets page
<isExposed>true<isExposed>
<targets>
    <target>lightning__RecordPage<target/>
</targets>

Then use @api to get recordId
import { LightningElement, api } from 'lwc';
export default class Sample extends LightningElement {
    @api recordId;
}

Way 2
Use CurrentPageReference
import { LightningElement, wire } from 'lwc';
import { CurrentPageReference } from 'lightning/navigation';
export default class Sample extends LightningElement {
    currentPageReference;

    @wire(CurrentPageReference)
    setCurrentPageReference(currentPageReference) {
        this.currentPageReference = currentPageReference;
        console.log('recordId: ' + this.currentPageReference.attributes.recordId);
    }
}

2022-11-29

Delete by record id use Schema SObjectType

public without sharing class CustomDeleteCmpController {

    @AuraEnabled(cacheable=true)

    public static String init(Id recordId) {

        // object name

        return recordId.getSobjectType().getDescribe().getLabel();

   }

 

    @AuraEnabled

    public static String doDelete(Id recordId) {

        try {

            String objApiName;

            RecordDelete.deleteLists(new List<SObject>{recordId.getSobjectType().newSObject(recordId)});

            if (String.isNotBlank(recordId)) {

                objApiName = String.valueOf(recordId.getSObjectType());

            }

            return objApiName;

        } catch (Exception ex) {

            throw ex;

        }

    }

}

Use 3rd Party Resource in LWC

import { loadStyle, loadScript } from 'lightning/platformResourceLoader';
// static resource
import myResourceName from '@salesforce/resourceUrl/myResourceName';


initianlized = false;
Use in renderedCallback() {
    if (this.initianlized) {
        return;
    }
    this.initianlized = true;
    Promise.all([
        loadStyle(this, myResourceName + '/css/myResourceName.css'),
        loadScript(this, myResourceName + '/js/myResourceName.js'),
    ]).then(() => {
        // do some thing
    });
}
myResourceName zip
/js/myResourceName.js
/css/myResourceName.css

2022-11-01

ReGet data without reload page

Reget data and raletive list data, but not reload page or redirect url.


In AURA

$A.get('e.force:refreshView').fire();


In LWC

import { getRecordNotifyChange } from 'lightning/uiRecordApi';

getRecordNotifyChange([{recordId: this.recordId1},{recordId: this.recordId2}]);

or

setTimeout(() => {
    eval("$A.get('e.force:refreshView').fire();");
},1000)

オブジェクト項目レベルセキュリティの一括管理

ツールなど経由して作成した項目はよく項目レベルセキュリティー権限をセットしていないです。

個別で項目レベルセキュリティーを設定するのは時間かかります。

一括管理の方法

1権限セット

2プロファイル:設定>プロファイル>項目レベルセキュリティ


2022-09-07

LWC: refresh record detail page

import { LightningElement, api } from 'lwc';

import { getRecordNotifyChange } from 'lightning/uiRecordApi';

 

export default class PageCmp extends LightningElement {

    @api recordId;

 

    doChanged() {

        // Refresh Detail Page

        getRecordNotifyChange([{recordId: this.recordId}]);

    }

}

DOMException: Failed to execute 'querySelectorAll' on 'Element': '#1' is not a valid selector.

<div id="1">HELLO</div>

When id is number likes: 1,

CSS.escape(1)

 

document.querySelector("#\\31");

 

2022-08-29

The selected number not displayed in the "lightning-combobox"?

The value of your options is a number, while event.detail.value holds a string.

After selecting an option, this. currentValue will hold a wrong value, i.e. '2022' instead of 2022.

convert to number: 
handleChange (event) {
    this.currentValue = +event.detail.value;
}

2022-07-02

Get browser type in Lightning Aura/LWC

In Aura

if ($A.get("$Browser.formFactor") != 'DESKTOP') {

    // do something for mobile only here

}


In LWC

import formFactorPropertyName from '@salesforce/client/formFactor'

if (formFactorPropertyName == "Large") {

    // Large—A desktop client.

    // Medium—A tablet client.

    // Small—A phone client.

}


Increase Width of Quick Action Modal Window

Aura

Add style tag to aura component.

<aura:component implements="force:lightningQuickAction,force:hasRecordId">

    <aura:html tag="style"> .slds-modal__container { min-width: 80vw; } </aura:html>

    <aura:attribute name="recordId" type="String" required="false" description="" access="global"/>

    <c:childCmp recordId="{!v.recordId}" onclose="{!c.closeModal}"></c: childCmp>

</aura:component>


LWC

Some issue of quick action in LWC.

Can not change type of Lightning Web Component after deploy.

Can not get recordId & objectApiName at init.

Not working in mobile & Experience(Community)

2022-06-25

2022-06-22

Salesforce lwc: datatable set multiple checkbox as radio checkbox

Default checkbox of lightning-datatable is multiple checkbox.

Set atrribute [max-row-selection="1"] can change to radio checkbox.




2022-06-16

Dataloader Error: Java Runtime (class file version 55.0), this version is up to 52.0

Java Runtime 52.0 -> Java 8

Java Runtime 55.0 -> Java 11 or new

So need install Java 11 or new to replace Java 8.


After installed java 11, do not forget to check you Environment Variables [JAVA_HOME].

Make sure JAVA_HOME is the new path to java 11 file.