Loading
ただいま大変多くのお問い合わせをいただいており、ご連絡までにお時間を頂戴しております続きを読む

component.find('auraId') method returns an array when only one component with matching ID is found during subsequent loads of the model

公開日: Jul 7, 2026
説明

The behavior is happening because of the way the aura framework stores the component id. For example when the modal is first open, the lightning component is registered to a map, at this point when we call component.find() we get an single object back, when we close and reopen the modal, the component is registered again but because a component with the same aura id already exists in the map, it is converted to a array and this array is returned to the user when they call component.find().

解決策

Always validate the return type of the method component.find('auraId') i.e. and proceed with business logic 

Example:

const cmps = component.find("auraId’");

if (!cmps) return;

if ($A.util.isArray(cmps)) {

    cmps.forEach(cmp => {

        // business logic

    })

} else {

    // business logic

}


In Nutshell, update the controller logic to handle both a single component reference and an array result from component.find. Use $A.util.isArray on the result, iterate from the end of the array, select the instance that is valid and rendered, and only then access value.

その他のリソース

Here's the reference documented Aura behaviour for component.find and consider planning migration of complex dynamic workflows from Aura to Lightning Web Components.

https://developer.salesforce.com/docs/atlas.en-us.lightning.meta/lightning/ref_jsapi_component_find.htm

https://developer.salesforce.com/docs/atlas.en-us.lightning.meta/lightning/js_cb_find_by_id.htm

ナレッジ記事番号

005388612

 
読み込み中
Salesforce Help | Article