• Dhanalakshmi Vellachamy 3
  • NEWBIE
  • 0 Points
  • Member since 2020

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 2
    Replies
I am trying set up a lightning component on the Account that will show the contact and what is the most recent activity associated with it. I tried using the Data table and now I am bale to get the contact records in the lightning component.User-added imageBut I am not sure how to include the subject and OwnerId from the Activities histories in to the Datatable column. Below is the Component and Aura enabled apex class

Apex Class
public with sharing class accountSummaryLightningComponent {
    
    @AuraEnabled
public static list<Contact> getRelatedList(Id recordId)
{
        
List<Contact> Conlist = [Select id,firstname,lastname,Contact_Salutation_First_and_Last_Name__c,(SELECT Id,Subject FROM ActivityHistories ORDER BY ActivityDate DESC LIMIT 1) from Contact where AccountId =: recordId and Key_contact__c = true];
return Conlist;
}
}

Aura component
 
<aura:component controller = "accountSummaryLightningComponent" implements="flexipage:availableForRecordHome,force:hasRecordId" access="global" >
    <aura:attribute name="recordId" type="Id" />
    <aura:attribute name="ContactList" type="Contact[]"/>
    <aura:attribute name="columns" type="List"/>
        
    <aura:handler name="init" value="{!this}" action="{!c.myAction}" />
    <lightning:card iconName="standard:work_capacity_usage" title="Key Contacts">
        <aura:if isTrue="{!not(empty(v.ContactList))}">
            <lightning:datatable data="{!v.ContactList }" 
                         columns="{!v.columns }" 
                         keyField="Id"
                         hideCheckboxColumn="true"/>           
            <aura:set attribute="else">
                <div Style="text-align : center"> " There are no key contacts " </div>
            </aura:set>
        </aura:if>
    </lightning:card>
</aura:component>

Controller
 
({
    myAction : function(component, event, helper) 
    { 
        component.set('v.columns', [
            {label: 'Contact Name', fieldName: 'linkName', type: 'url',
             typeAttributes: {label: { fieldName: 'Contact_Salutation_First_and_Last_Name__c' }, target: '_blank'}}
        ]);
        
        var ConList = component.get("c.getRelatedList");
        ConList.setParams
        ({
            recordId: component.get("v.recordId")
        });
        
        ConList.setCallback(this, function(data) 
        {          
            var state = data.getState();
            if (state === "SUCCESS") {
                var records =data.getReturnValue();
                records.forEach(function(record){
                    record.linkName = '/'+record.Id;
                });
                 component.set("v.ContactList", data.getReturnValue());            
            }
        });
        $A.enqueueAction(ConList);
    }
})

Can anyone please help how to include the Subject and Owner of the Activity in the datatable​​​​​​​
Hi have a lightning component datatable that is populated by a query with a subquery in it. I need the second column to be poulated with a value from the subquery but I can't seem to figure out how to set the field name for the the subquery field. 

Screen shot: (RPF Con should map to sub query field.
User-added imageApex Class
public class RFPOppListController {

        @AuraEnabled
    public static List <Opportunity> fetchOpps (String oppId) {
        //Qyery 10 
        List<Opportunity> oppList = [SELECT Opportunity.Name, (select Contact__r.Name from Opportunity_Contact_Roles__r where Contact_roles__c = 'RFP consultant') FROM Opportunity];
        //return lis
        return oppList;
    }
}

Component:
<aura:component controller="RFPOppListController" access="global" implements="force:appHostable,flexipage:availableForAllPageTypes,force:hasRecordId">

    <aura:attribute type="Opportunity[]" name="oppList"/>
    <aura:attribute name="mycolumns" type="List"/>
    <aura:attribute name="updatedRecord" type="Object[]" />


     
    <aura:handler name="init" value="{!this}" action="{!c.fetchOPPS}"/>
     
    <lightning:datatable aura:id="oppsDataTable"
                         data="{! v.oppList }"
                         columns="{! v.mycolumns }"
                         keyField="Id"
                         hideCheckboxColumn="true"
                         onsave ="{!c.onSave}"
                         />
     
</aura:component>

Controller
({
    fetchOPPS : function(component, event, helper) {
        helper.fetchOPPSHelper(component, event, helper);    

    }
})
Helper
({
    fetchOPPSHelper : function(component, event, helper) {
        component.set('v.mycolumns', [
            {label: 'Opp Name', fieldName: 'Name', editable:'true', sortable:'true', type: 'text'},          
            {label: 'RFP Con', fieldName: 'Opportunity_Contact_Roles__r.Contact__r.Name', editable:'true', sortable:'true', type: 'date'}   
            ]);
        debugger;
        var action = component.get("c.fetchOpps");      
        var operID = component.get("v.recordId");
        console.log("operID" + operID);
        action.setParams({
            oppId:operID
        });
        action.setCallback(this, function(response){
            var state = response.getState();
            if (state === "SUCCESS") {
                component.set("v.oppList", response.getReturnValue());
            }
        }); 
        $A.enqueueAction(action);
    }
})


BTW, here is a debugger screenshot of of the value I am trying to display:
User-added image
Hi ,
I got a requirement to create a case in Salesforce whenever an incident is created in ServiceNow with Assignment group as "Salesforce".

Let me know if you have any ideas or if anyone has implemented this.

Thanks in advance.

Rao.
  • January 30, 2019
  • Like
  • 0