function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Ashu sharma 38Ashu sharma 38 

I am stucking to show contact activity in my custom object using lighting component

Hi,

I have created a component to show the contact activity in my object.

public class ContactActivityHistory {
    
    @auraEnabled
    
    public static list<Task> getContactTask(id contactId){
        system.debug('contactId ' +contactId );
        list<task> contactTask=new list<task>();
        list<Application__c> appList=[select id,Contact__c from Application__c where Contact__c=:contactId];
       
      //  Application__c appList=[select id,Contact__r.id,(select id,Subject,Description,Who.Name,ActivityDate From Tasks ) 
                             //  from  Application__c where Contact__r.id= :ContactId];
   
        list< Contact> cons=new list<Contact>();
        cons=[select id from contact where id=:appList[0].Contact__c];
       //  cons= [select id,(select id,subject,Description,Who.Name,ActivityDate From Tasks) from contact where id=:appList[0].Contact__c];
    list<Task> tsk=[select id,whoId from task where whoId=:cons];
        system.debug('Task' +tsk);
        return tsk;
    }
    
}

Componenet


<aura:component implements="flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes"
                access="global" controller="ContactActivityHistory">
    
    <aura:attribute name="recordId" type="Id"/>
   
    <aura:attribute name="newTask" type="Task" default="{'sobjectType':'Task'}"/>
    <aura:attribute name="tasks" type="Task[]"/>
    <aura:handler name="init" value="{!this}" action="{!c.doInit}" />
    
    <aura:iteration items="{!v.tasks}" var="item">
        {!item.Subject}, {!item.ActivityDate}<br/>
    </aura:iteration>
    
</aura:component>

Js

({
    
    doInit : function(component, event, helper)
    {
        console.log('Test activity');
        var action = component.get("c.getContactTask");
        console.log('Test Activity @@@@');
        //  var action2=component.get('v.recordId');
        action.setParams({            
            "ContactId" : component.get('v.recordId')
        });
        
        console.log('Test my contact record activity ' +component.get('v.recordId'));
        action.setCallback(this, function(response) {
            var state = response.getState();
            if(state === "SUCCESS"){
                var records = response.getReturnValue();
                console.log('Server-> ' + JSON.stringify(records));
                
                var newItems=[];
                for (var i=0; i< records.length; i++)
                {
                    var record = records[i];
                    console.log('record-> ' + JSON.stringify(record));
                    
                    //   var Item = {title: record.Name, id: record.Id, status: "Unassigned"};
                    //  console.log('Item-> ' + JSON.stringify(Item));
                    
                    newItems.push(record);
                    console.log('newItems-> ' + JSON.stringify(newItems));
                }
                //component.set("v.tasks", newItems);
                
                
            } 
            else if (state === "ERROR") {
                var errors = response.getError();
                if (errors) {
                    if (errors[0] && errors[0].message) {
                        console.log("Error message: " + 
                                    errors[0].message);
                    }
                }
                
            }            
            
        });
        $A.enqueueAction(action);
        
        
    }  
})
sfdcBahusfdcBahu
In the controller, why dont you use directly as

list<Task> tsk = [select id,whoId from task where whoId=:ContactId];

in the JS, this should not be commented right, as this is where you pass the data to the front end variable.
                //component.set("v.tasks", newItems);
 
Ashu sharma 38Ashu sharma 38
Hi sfdcBahu,

Suggest me in query ---Actually I am trying to make functinality in application object I have to show the contact activity.

Thanks