I'm trying to build a very simple survey type component that has three objects: Questions [FFS_Key_Area_Bank__c; the questions], Results[FFS_Results__c; the rating on a particular question], Surveys [FFS_Survey__c; a collection of responses with responses as a related list]. Responses is a junction object with lookup relationships to Questions and Surveys.

The questions are each related to a distinct department, and I can successfully query for questions related to a department and have them appear in the component via an aura:iteration over the attribute that holds the questions. (This part works without a hitch.)

The problem that I have, however, is that I need to somehow relate the question from the Questions object to the rating for that particular question on the Responses object. My first thought was to use a field on the Questions object called "FFS Key Area" because that is the question text. I'd rather, however, use the question ID, of course. I feel like this should be basic, but I'm at a standstill.

I think the most relevant part of the code is in the <aura:iteration> over the Questions in FFS_Key_Area_Bank__c, so I'll only include that for now.

The code accomplishes iterating over the correct questions that are returned from a SOQL query. You can see, however, that there are no fields from FFS_Results being populated. If I alter the <lightning:input> to include a value of {!v.results.Key_Area_Bank__c} (This is the lookup field name from Results to Questions), the fields are, obviously blank. What I want, again, is for the value of {!questions.FFS_Key_Area__c} to be populated on to {!v.results.Key_Area_Bank__c}.

You'll also notice that there is no field for the rating. What I add a <lightning:input> with a value of {!v.results.Rating__c}, I get as many fields as are returned in the questions iteration, but the fields are tied together (e.g., typing in one populates all).

Component Markup (I'll add Controller markup, if that's helpful)

<lightning:layout verticalAlign="center">
        <lightning:layoutItem flexibility="auto" padding="around-medium">
            <lightning:card class="slds-card__body slds-card__body_inner"
                    iconName="action:new_group" title="Questions">

                    <aura:iteration items="{!v.questions}" var="questions">
                        <lightning:layoutItem flexibility="auto" padding="around-small">
                                <lightning:input label="Key Area"

One final note: when I run this code (back ticks aren't showing for template literal) let newQuestions = component.get("v.questions"); `console.log((newQuestions ${JSON.stringify(newQuestions)}));``

I get the following output that reflects the SOQL query (object changes based on department, but this is illustrative):

newQuestions [
    {"Id":"a0Z2C000000Y2bcUAC","Name":"FFSQ-0000","FFS_Key_Area__c":"Admin Question 1","Department_Lookup_Name__c":"Administration"},       
    {"Id":"a0Z2C000000Y2bhUAC","Name":"FFSQ-0001","FFS_Key_Area__c":"Admin Question 2","Department_Lookup_Name__c":"Administration"},
    {"Id":"a0Z2C000000Y2bmUAC","Name":"FFSQ-0002","FFS_Key_Area__c":"Admin Question 3","Department_Lookup_Name__c":"Administration"}

If I run similar code for "v.results" I don't get anything, even when the <lightning:input> with a value of {!v.results.Rating__c} is added.

Thanks in advance for advice

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.