2

So, I have been losing my mind over this for a few days now.

Scenario: I have a component that displays a custom modal.

this a snippet of code, that takes care of that

showModal: function (component, event, helper) {

        var objectFieldsNew = component.get('v.objectFields');
        console.log('objectFields before the component creation' , objectFieldsNew)
        var modalBody;

        console.log('OBJECT FIELDS list',objectFieldsNew.accessibleObjectFields);
        $A.createComponents([
                ["c:relatedRecords", {"mappingDto" : component.get('v.mappingDto'), "objectFields" : objectFieldsNew}],

            ],
            function (components, status) {
                if (status === "SUCCESS") {
                    modalBody = components[0];

                    component.find('overlayLib').showCustomModal({
                        header: "Application Confirmation",
                        body: modalBody,

                        showCloseButton: true,
                        cssClass: "my-modal,my-custom-class,my-other-class",
                        closeCallback: function () {
                            alert('You closed the alert!');
                        }
                    })
                }
            }
        );
    }

As you could have noticed my modal component name is

relatedRecords.cmp

 <aura:attribute name='objectFields' type='RelatedFieldsDTO' />
 <aura:attribute name='mappingDto' type='MappingDto'/>
<div class="slds-grid">
        <div class="slds-col"> <c:relatedRecordsColumn      objectFields='{!v.objectFields}' mappingDto='{!v.mappingDto}'     selectedField="{!v.selectedField1}"/> </div>

There is another component

relatedRecordsColumn

, where the freaky stuff happens.

EDIT 2: my lightning:select tag wasn't closed by the /lightning:select, now when I create a new String[] from my RelatedFieldsDTO, I can iterate over options. Exception is still thrown when I continue using my DTO though. I will use this workaround as I need to get this task finished, but the original question still remains unanswered and still bugs me.

 <aura:attribute name='objectFields' type='RelatedFieldsDTO' />
<aura:attribute name='mappingDto' type='MappingDto'/>

<lightning:select label="Select Field" value="v.selectedField">

<aura:iteration items="{!v.objectFields.accessibleObjectFields}" var="objectField" >

    <option value='{!objectField}' selected="{! v.selectedField == objectField ? 'true' : 'false'}">{!objectField} </option>

</aura:iteration>
</lightning:select>

My modal is working as expected, but the iteration throws aura:exception. It doesn't make sense at all, as I have done this so many times, but not in the modal (iterating over a list of Strings).

the last thing is Stack Trace from SF:

aura://ComponentController:
org.auraframework.throwable.AuraExecutionException:
org.auraframework.impl.root.component.IterationProvider: org.auraframework.throwable.AuraRuntimeException: attribute is of the wrong type: expected java.lang.Iterable but got java.util.LinkedHashMap

Does anyone have any idea what am I doing wrong?

EDIT 1: added

RelatedFieldsDTO

code

global with sharing class RelatedFieldsDTO {
@AuraEnabled global List<String> accessibleObjectFields = new    List<String>();
@AuraEnabled global Map<String , String> objectFieldToTargetTypeMap =    new Map<String , String>();

}

4
  • What is type of attribute objectFields.accessibleObjectFields is it map or List Aug 28, 2018 at 8:12
  • sorry for not mentioning it, but yeah its List of Strings. Aug 28, 2018 at 8:13
  • can you add RelatedFieldsDTO class code here Aug 28, 2018 at 8:18
  • @ManjotSingh added in the original post Aug 28, 2018 at 8:24

1 Answer 1

1

TL;DR: I suggest that you change the type of your attributes to Map.

By being too specific with RelatedFieldsDTO and MappingDto you are forcing 'unnecessary' type conversions on the server side. What happens is that:

  1. your data lives as JS objects in the browser
  2. it is converted to JSON in the HTTP request that fetches your c:relatedRecords component
  3. the server converts it to the RelatedFieldsDTO and MappingDto Java types (yes, Apex is running on Java).

This last operation is probably what is causing your problem. So, unless you have a very good reason to keep these types on the client side (which does not appear to be the case looking at your sample code), just switch your Lightning attributes' type to Map.

Here is an interesting blog post that covers the topic of client/server type conversion in Lightning.

4
  • I have actually thought about this, and already tried using simple String[] as an attribute for the iteration, with no luck. I am beginning to suspect that the error is happening somewhere else. Aug 28, 2018 at 8:45
  • Unless I misunderstood your data structure or your comments, objectFields with type String[] won't do with because of the level of nested data. RelatedFieldsDTO translates to {accessibleObjectFields: [], objectFieldToTargetTypeMap: {}} that is a Map type.
    – POZ
    Aug 28, 2018 at 11:51
  • now I fully understand what you meant, by your comment, I will try to go over it tomorrow and If I am successful, I will mark this as a best answer. Thank you. Aug 29, 2018 at 6:36
  • your explanation was helpful, so I am rating it as the bet answer. I actually had to re-write whole modal creation in a way, that doesn't dynamically create components, rather I'm displaying modal component if <aura:if> and pass the attributes upon the creation. Sep 12, 2018 at 11:14

You must log in to answer this question.

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