+ Start a Discussion
Ashu sharma 38Ashu sharma 38 

How to display activity for related object in object?

Hi,

I have a requirement,have to show Custom object activity in contact related list.::
Contact and Custom__c,In this custom object I have to show activity of contacts.

Thanks.
Ashima nidhiAshima nidhi
Please see the below doc to do the same , However there should be a relationship between the new object and contact to do the same.

https://help.salesforce.com/HTViewHelpDoc?id=customizing_related_lists.htm

Hope above information was helpful.

Please mark as Best Answer so that it can help others in the future.
sachinarorasfsachinarorasf
Hi Ashu Sharma,

I have gone through your problem. 

I think you have to create an Aura Component. and show all related contact activities.

The below URL can help to create an Aura Component. 
1.https://www.lightningdesignsystem.com/components/activity-timeline/
2.https://chuzoneill.wordpress.com/2015/12/22/tutorial-activity-timeline-lightning-component/   


I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.

Thanks and Regards,
Sachin Arora
Ashu sharma 38Ashu sharma 38
Hi Sachin,

Thanks for your reply,
As per my req I am trying,but not getting appropriate on it.Kindly suggesting on this follow:

 public static list<Task> getContactTask(string contactId){
       
        system.debug('contactId ' +contactId );
        list<task> contactTask=new list<task>();
        list<contact> consList=[select id,name,(select id from applications__r) from contact where id=:contactId];
        list<Task> tsk=[select id,whoId from task where whoId=:consList[0].id];
        system.debug('Task' +tsk);
        return tsk;
        
    }
    
}


Cmp:
<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 action=component.get('v.recordId');
        console.log(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));
                alert("From server: " + response.getReturnValue());
                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);
        
        
    }  
})


As not working for me...

Thanks..