0

I am trying to use forceChatter:feed from (https://developer.salesforce.com/docs/component-library/bundle/forceChatter:feed/documentation).

The below code is working fine and the result is as expected.

    <aura:component controller="chatterController" implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes,force:lightningQuickAction" access="global" >
    <aura:handler name="init" action="{!c.doInit}" value="{!this}" access="global" />
      <aura:attribute name="contactList" type="id" />
    <forceChatter:feed type="Record" subjectId="a091y000000fXREAA2" /> //Passing Record Id directly
</aura:component>

Whereas if I pass the SubjectId with some attribute value, results are not getting displayed as expected.

<aura:component controller="chatterController" implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes,force:lightningQuickAction" access="global" >
    <aura:handler name="init" action="{!c.doInit}" value="{!this}" access="global" />
      <aura:attribute name="contactList" type="id" />
    <forceChatter:feed type="Record" subjectId="{!v.contactList}" /> //Passing Variable which has record-id(a091y000000fXREAA2) directly
</aura:component>

Not able to find what's the exact reason why the results are not displayed properly when I pass subjected with a variable which has the record Id.

2
  • If the hardening is working but the variable is not, I would suggest to check the JS or simply try and display the value of {!v.contactList}
    – manjit5190
    Feb 18, 2021 at 18:00
  • Thanks, @manjit5190, but i tried displaying {!v.contactList} and it's getting displayed, whereas the same isn't working when I put it as a variable in the tag Feb 19, 2021 at 2:46

1 Answer 1

1

I have found the answer to my question. First, let me explain why the above thing is not working. As I am getting Id from the controller and in return, the Id is getting returned from the Apex controller and it's taking time as it is an asynchronous process and hence when the tag is getting rendered it is getting rendered as undefined.

Hence, to solve this issue, add this component in the controller and dynamically create it as follows:

$A.createComponent(
                    "forceChatter:feed", {
                        "context": "RECORD",
                        "subjectId": response.getReturnValue()
                    },
                    function(recordFeed) {
                        if (component.isValid()) {
                            var body = component.get("v.body");
                            body.push(recordFeed);
                            publisher.set("v.body", body);
                        }
                    });

This will solve your issue like a charm!

You must log in to answer this question.

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