0

I have a custom Lightning component which I have recently added a new attribute to using the Salesforce Developer Console:

<!--Child.cmp-->
<aura:component>
    <aura:attribute name="existingAttribute" type="String" required="true"/>
    <!-- This is a new attribute I've added today-->
    <aura:attribute name="newAttribute" type="String" required="true"/>
<aura:component/>

However, when I come to update the existing code in a parent component - I'm unable to save the component due to an error:

FIELD_INTEGRITY_EXCEPTION

Failed to save Parent.cmp: The attribute "newAttribute" was not found on the COMPONENT markup://c:Child: Source

The code for the parent component contains the component nested deep into the code, using an aura:iteration and an aura:if.

<!--Parent.cmp-->
<div>
    <form>
        <aura:iteration items="{!v.items}" var="item">
            <div>
                <aura:if isTrue="{!or(or(item.type == 'text', item.type == 'password'), item.type == 'email')}">
                    <c.Child existingAttribute="{!item.existing}" newAttribute="{!item.new}" />
                <aura:if/>
            </div>
        </aura:iteration>
    </form>
</div>

The component can be saved again if I remove the newAttribute attribute.

From my viewpoint - there is no errors in terms of formatting or setting up the aura:attribute - and it should work.

And the interesting thing about this - is that the <c.Child /> component line will work if it has a higher level in the depth of the code - it doesn't seem to want to work if it's nested five levels deep...

<!--Parent.cmp-->
<!-- Works -->
<div>
    <!-- Works -->
    <form>
        <!-- Works -->
        <aura:iteration items="{!v.items}" var="item">
            <!-- Works -->
            <div>
                <!-- Doesn't Work -->
                <aura:if isTrue="{!or(or(item.type == 'text', item.type == 'password'), item.type == 'email')}">
                    <!-- Doesn't Work -->
                <aura:if/>
            </div>
        </aura:iteration>
    </form>
</div>

Am I missing something? Is this a bug? How would I solve this?

Any help would be massively appreciated.

5
  • My first thought was that the Child component wasn't successfully deployed to the server after you added that attribute, but that wouldn't explain it working sometimes and not others. Is it possible your actual code is slightly different from the example code you posted? Jun 4, 2021 at 13:09
  • Just to be sure, you mean c:Child and not c.Child, right? That would definitely cause problems if you did that.
    – sfdcfox
    Jun 4, 2021 at 13:17
  • @sfdcfox - I've been using c.Child and it seems to be working ok - can you tell me why I should be using c:Child instead? I want to assume it might be something that's more recent? Jun 4, 2021 at 13:22
  • Small update on the situation - I've copied the code into an IDE on my machine and used sfdx to deploy the changes - that seemed to work perfectly fine, so my only conclusion with this is that it's more of a bug with the Developer Console within Salesforce. Jun 4, 2021 at 13:25
  • I can only presume it's a bug. It has been c:Child since the original release. The c.Child syntax appears nowhere in the documentation at all.
    – sfdcfox
    Jun 4, 2021 at 13:35

1 Answer 1

0

c.Child is the incorrect component name, it should be c:Child. The reason why is because of XML and how names are defined. The <x:y> syntax means "the component y in the namespace x," while <x.y> means "the component x.y in the default namespace." As you can hopefully see, these are two different definitions, and should yield different results.

If we look at the naming rules, we find that names:

  • Must begin with a letter
  • Must contain only alphanumeric or underscore characters
  • Must be unique in the namespace
  • Can’t include whitespace
  • Can’t end with an underscore
  • Can’t contain two consecutive underscores

As you can see, you're technically trying to refer to a component by the wrong name. I'm honestly quite surprised it ever compiled for any reason. I'd log that as a bug, perhaps. Components must always be referenced to by <namespace:name> Under no circumstances are . allowed in any component name or attribute.

You'll also probably want to read more about namespaces.

1
  • Thanks for your answer and explaining to me why I should be using c:Child - I'm definitely going to take it onboard and make sure I use it going forward. Jun 7, 2021 at 10:13

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .