Loading

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

Fecha de publicación: Jul 7, 2026
Descripción

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().

Solución

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.

Recursos adicionales

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

Número del artículo de conocimiento

005388612

 
Cargando
Salesforce Help | Article