• Richard Mar
  • NEWBIE
  • 30 Points
  • Member since 2015
  • Technical Lead/Salesforce Developer
  • Neuberger Berman

  • Chatter
    Feed
  • 1
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 4
    Replies
I'm trying to create a lightning component for a custom object called Comments__c.  Comments__c can be used for Accounts and/or Contacts.

I would like the LC to be dynamic enough where I just have one lightning component for both Accounts and Contacts.  The purpose of the lightning component is to display the comments on the record detail page of either the Account or Contact.  If it's a Contact Record, I would like to display the Account comments as well as the Contact comments.

I'm stuck as to how I can make this lightning component reusable for Contacts.  Here is my code thus far

ListComments.cmp
<aura:component controller = "CommentsController" implements="flexipage:availableForRecordHome,force:hasRecordId" access="global" >
    <aura:attribute name="recordId" type="Id" />
    <aura:attribute name="newComment" type="Object"/>
    <aura:attribute name="sObjects" type="sObject[]"/>
    <aura:attribute name="CommentList" type="Comment__c[]" />
    <aura:handler name="init" value="{!this}" action="{!c.myAction}" />
    
    <aura:if isTrue="{!not(empty(v.CommentList))}">
    <lightning:card>
        <aura:set attribute="actions">
            <ui:button label="New Comment" press="{!c.createRecord}"/>
        </aura:set>
        <p class="slds-p-horizontal_small slds-text-align_center">
            <aura:iteration  items="{!v.CommentList}" var="com">
                <div class="uiOutputRichText" linkify="true" >
                    <p><ui:outputRichText aura:id="outputRT" value="{!com.Comment__c}" /></p>
                </div>
            </aura:iteration>
        </p>
    </lightning:card>
    </aura:if>
    
    
</aura:component>

CommentsController.apxc
public with sharing class CommentsController {
@AuraEnabled
    public static list<Comment__c> getRelatedList(Id recordId)
    {
        List<Comment__c> commlist = [Select id, active__c, comment__c,contact__c,createdbyid,createddate from Comment__c where Account__c=: recordId AND Active__c = true ORDER BY CreatedDate ASC];
        return commlist;
    }
}

ListCommentsController.js
({
    myAction : function(component, event, helper) 
    {
        var commList = component.get("c.getRelatedList");
        commList.setParams
        ({
            recordId: component.get("v.recordId")
        });
        
        commList.setCallback(this, function(data) 
        {
             component.set("v.CommentList", data.getReturnValue());
        });
        $A.enqueueAction(commList);
    },
    createRecord : function (component, event, helper) {
        var createRecordEvent = $A.get("e.force:createRecord");
        createRecordEvent.setParams({
            "entityApiName": "Comment__c",
            "navigationLocation" : "LOOKUP",
            "defaultFieldValues":{
                "Account__c": component.get("v.recordId")
            },
            "panelOnDestroyCallback": function(event) {
                var urlEvent = $A.get("e.force:navigateToURL");
                urlEvent.setParams({
                    "url": "/lightning/r/Account/"+component.get("v.recordId")+"/view"
                });
                urlEvent.fire();
            }
        });
        createRecordEvent.fire();
        
    }
})


 
I'm trying to create a lightning component for a custom object called Comments__c.  Comments__c can be used for Accounts and/or Contacts.

I would like the LC to be dynamic enough where I just have one lightning component for both Accounts and Contacts.  The purpose of the lightning component is to display the comments on the record detail page of either the Account or Contact.  If it's a Contact Record, I would like to display the Account comments as well as the Contact comments.

I'm stuck as to how I can make this lightning component reusable for Contacts.  Here is my code thus far

ListComments.cmp
<aura:component controller = "CommentsController" implements="flexipage:availableForRecordHome,force:hasRecordId" access="global" >
    <aura:attribute name="recordId" type="Id" />
    <aura:attribute name="newComment" type="Object"/>
    <aura:attribute name="sObjects" type="sObject[]"/>
    <aura:attribute name="CommentList" type="Comment__c[]" />
    <aura:handler name="init" value="{!this}" action="{!c.myAction}" />
    
    <aura:if isTrue="{!not(empty(v.CommentList))}">
    <lightning:card>
        <aura:set attribute="actions">
            <ui:button label="New Comment" press="{!c.createRecord}"/>
        </aura:set>
        <p class="slds-p-horizontal_small slds-text-align_center">
            <aura:iteration  items="{!v.CommentList}" var="com">
                <div class="uiOutputRichText" linkify="true" >
                    <p><ui:outputRichText aura:id="outputRT" value="{!com.Comment__c}" /></p>
                </div>
            </aura:iteration>
        </p>
    </lightning:card>
    </aura:if>
    
    
</aura:component>

CommentsController.apxc
public with sharing class CommentsController {
@AuraEnabled
    public static list<Comment__c> getRelatedList(Id recordId)
    {
        List<Comment__c> commlist = [Select id, active__c, comment__c,contact__c,createdbyid,createddate from Comment__c where Account__c=: recordId AND Active__c = true ORDER BY CreatedDate ASC];
        return commlist;
    }
}

ListCommentsController.js
({
    myAction : function(component, event, helper) 
    {
        var commList = component.get("c.getRelatedList");
        commList.setParams
        ({
            recordId: component.get("v.recordId")
        });
        
        commList.setCallback(this, function(data) 
        {
             component.set("v.CommentList", data.getReturnValue());
        });
        $A.enqueueAction(commList);
    },
    createRecord : function (component, event, helper) {
        var createRecordEvent = $A.get("e.force:createRecord");
        createRecordEvent.setParams({
            "entityApiName": "Comment__c",
            "navigationLocation" : "LOOKUP",
            "defaultFieldValues":{
                "Account__c": component.get("v.recordId")
            },
            "panelOnDestroyCallback": function(event) {
                var urlEvent = $A.get("e.force:navigateToURL");
                urlEvent.setParams({
                    "url": "/lightning/r/Account/"+component.get("v.recordId")+"/view"
                });
                urlEvent.fire();
            }
        });
        createRecordEvent.fire();
        
    }
})


 
Hi, I have a requirement where i want to change the value of attribute insode the aura:if.
I want to set the value of disableActivityDate to True if  BranchValue!=null .Here is my code:
 <aura:attribute name="disableActivityDate" type="String" default="true"/>
 <aura:If isTrue="{!v.BranchValue!=null}">                              
   <lightning:inputField fieldName="Activity_Date__c" aura:id="dateField" onchange="{!c.resetActivityTimeSelection}" disabled="{!v.disableActivityDate}"/>   
                       </lightning:layoutItem>
                      </aura:If>