You need to sign in to do that
Don't have an account?

How to passing parameter from apex class to js
Hi,
I am trting to populate the contacts task in my application object,but I am trying to passng the contactId ,confuse over it how to do.
Kindly suggest!!!!
Here is my code.
public static list<Task> getContactTask(string 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;
}
}
<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);
}
})
Thanks
I am trting to populate the contacts task in my application object,but I am trying to passng the contactId ,confuse over it how to do.
Kindly suggest!!!!
Here is my code.
public static list<Task> getContactTask(string 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;
}
}
<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);
}
})
Thanks
i did not understand the problem in your code,you are passing parameter correctly ,are yu using the component on contact page or another ?
Thanks for your reply..
Its now working..
<aura:component controller = "ContactTaskonApplication" implements="flexipage:availableForRecordHome,force:hasRecordId" access="global" >
<aura:attribute name="recordId" type="Id" />
<aura:attribute name="sObjectName" type="String" />
<aura:handler name="init" value="{!this}" action="{!c.doInit}" />
<aura:attribute name="newTask" type="Task" default="{'sobjectType':'Task'}"/>
<aura:attribute name="tasks" type="Task[]" default="{'sobjectType' : 'Task'}"/>
<ul class="slds-timeline">
<div class="isExpendable slds-timeline__item_expandable slds-timeline__item_task" aura:id="expId">
<aura:iteration items="{!v.tasks}" var="item" >
<div class="slds-media " >
<div class="slds-media__figure">
<button class="slds-button slds-button_icon"
onclick="{!c.toggleAcitivity}"
title="test"
aria-controls="task-item-base">
<lightning:icon iconName="utility:switch"
size="x-small"
class="slds-button__icon slds-timeline__details-action-icon"/>
</button>
<div class="slds-icon_container" title="task">
<lightning:icon iconName="standard:task" size="small"/>
</div>
</div>
<div class="slds-media__body">
<div class="slds-grid slds-grid_align-spread slds-timeline__trigger">
<div class="slds-grid slds-grid_vertical-align-center slds-truncate_container_75 slds-no-space">
<h3 class="slds-truncate" title="{!item.Subject}">
<strong>{!item.Subject}</strong>
</h3>
</div>
</div>
<p class="slds-m-horizontal_xx-small">
<lightning:formattedDateTime value="{!item.ActivityDate}"/>
</p>
<!-- expandable section start-->
<article class="slds-box slds-timeline__item_details slds-theme_shade slds-m-top_x-small slds-m-horizontal_xx-small"
id="task-item-base"
aria-hidden="true">
<ul class="slds-list_horizontal slds-wrap">
<li class="slds-grid slds-grid_vertical slds-size_1-of-2 slds-p-bottom_small">
<span class="slds-text-title slds-p-bottom_x-small">Priority</span>
<span class="slds-text-body_medium slds-truncate" title="{!item.Priority}">{!item.Priority}</span>
</li>
<li class="slds-grid slds-grid_vertical slds-size_1-of-2 slds-p-bottom_small">
<span class="slds-text-title slds-p-bottom_x-small">Status</span>
<span class="slds-text-body_medium slds-truncate" title="{!item.Status}">{!item.Status}</span>
</li>
<li class="slds-grid slds-grid_vertical slds-size_1-of-2 slds-p-bottom_small">
<span class="slds-text-title slds-p-bottom_x-small">Subject</span>
<span class="slds-text-body_medium slds-truncate" title="{!item.Subject}">{!item.Subject}</span>
</li>
<li class="slds-grid slds-grid_vertical slds-size_1-of-2 slds-p-bottom_small">
<span class="slds-text-title slds-p-bottom_x-small">Due Date</span>
<span class="slds-text-body_medium slds-truncate" title="{!item.Due_Date__c }">{!item.Due_Date__c}</span>
</li>
</ul>
</article>
</div>
</div>
</aura:iteration>
</div>
</ul>
</aura:component>
JS
({
doInit: function(component, event, helper){
console.log(" doInit");
var action = component.get("c.getContactTask");
action.setParams({ recordId : component.get("v.recordId")});
action.setCallback(this, function(response) {
var list = response.getReturnValue();
console.log('<<<Return Value>>>'+JSON.stringify(response.getReturnValue()));
//component.set("v.selectedValue", list);
var newItems=[];
for (var i=0;i< list.length; i++)
{
var record = list[i];
console.log('record-> ' + JSON.stringify(record));
var Item = {Subject: record.Subject, id: record.Id, ActivityDate:record.ActivityDate};
console.log('Item-> ' + JSON.stringify(Item));
newItems.push(Item);
console.log('newItems-> ' + JSON.stringify(newItems));
}
component.set("v.tasks",newItems);
console.log('Test my contact Task' +component.set("v.tasks",list));
})
console.log(" doInit3");
$A.enqueueAction(action);
},
toggleAcitivity : function(component, event, helper) {
// toggle 'slds-is-open' class to expand/collapse activity section
$A.util.toggleClass(component.find('expId'), 'slds-is-open');
}
})