• Andreas Christides
  • NEWBIE
  • 0 Points
  • Member since 2016
  • CRM Consultant
  • Gfi


  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 3
    Questions
  • 2
    Replies
Hi all, 

I want to create a Lightning Component that would retrieve Tasks linked to a specific Case. 

Here is the code I got from a component that retrieves Tasks based on the UserId : 
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
MyTasksComponent.cmp
<aura:component controller="tasksController" access="global" implements="flexipage:availableForAllPageTypes,force:appHostable">
    
    <aura:attribute name="heading" type="String" access="global" default="Mes Tâches"/> 
    <aura:attribute name="tasks" type="Task[]" />
    <aura:handler name="init" value="{!this}" action="{!c.doInit}" />
    
    <div class="My-slds-card">
    <article class="slds-card slds-card--narrow">
      <div class="slds-card__header slds-grid">
        <header class="slds-media slds-media--center slds-has-flexi-truncate">
           <div class="slds-media__body">
            <h2>
                <span class="slds-text-heading--small">{!v.heading}</span>
            </h2>
          </div>
        </header>
       </div>
  
      <div class="slds-card__body">
        <div class="slds-card__body--inner">
            <div>
                <ui:inputSelect aura:id="selection" class="slds-picklist" change="{!c.changeFilter}">
                    <ui:inputSelectOption text="AllOpen" label="Toutes en cours"/>
                    <ui:inputSelectOption text="Overdue" label="En retard"/>
                    <ui:inputSelectOption text="Today" label="Aujourd'hui" />
                    <ui:inputSelectOption text="TodayOverdue" label="Aujourd'hui + en retard"/>
                    <ui:inputSelectOption text="Tomorrow" label="Demain"/>
                    <ui:inputSelectOption text="NextSevenDays" label="7 prochains jours" value="true"/>
                    <ui:inputSelectOption text="NextSevenDaysOverdue" label="7 prochains jours + en retard"/>
                    <ui:inputSelectOption text="ThisMonth" label="Mois en cours"/>
                </ui:inputSelect>            
            </div>
        </div> 
        <br/>  
        <div class="slds-card__body--inner">
        <aura:iteration items="{!v.tasks}" var="task">
          <div class="slds-tile">
            <h3 class="slds-truncate" title="Related Record Title 1">
                <a href="{! '#/sObject/' + task.Id + '/edit'}"  class="ui-replce-style">
                    <lightning:icon iconName="standard:task" size="small" alternativeText=""/> &emsp;{!task.Subject}
                </a>
                <ul class="list">
                    <li>
                         {!task.Type} | {!task.Status} | <ui:outputDate value="{!task.ActivityDate}"/> <br/>
                    </li>
                </ul>
              </h3>
          </div>
        </aura:iteration> 
        </div>
      </div>
        <div class="slds-card__footer"><a href="{! '#/sObject/Task/home'}"  class="ui-replce-style">View All</a></div>
    </article>
    </div>
    
</aura:component>

MyTasksComponentController.js
({
    doInit : function(component) {
        var action = component.get("c.MyTask");   

        // get the value for Label field, if empty then default it to 'My Tasks'
        var isEmptyHeading = $A.util.isEmpty(component.get("v.heading"));
        if (isEmptyHeading) {
            component.set("v.heading","Mes Tâches");
         }

        action.setCallback(this, function(data) {
            console.log(data.getReturnValue());
            component.set("v.tasks", data.getReturnValue());
         });
        $A.enqueueAction(action);
    },
    
    changeFilter:function(component,event){
        var action = component.get("c.TaskByFilter");
        var selectCmp = component.find("selection");
        var selectVal = selectCmp.get("v.value");
        console.log('Selected Value '+selectVal);
        action.setParams({
          "fltr": selectVal
          
        });
        action.setCallback(this, function(data) {
            console.log(data.getReturnValue());
            component.set("v.tasks", data.getReturnValue());
        });
        $A.enqueueAction(action);
        
    }
    
   
    
})

tasksController.apxc
public class tasksController {
     @AuraEnabled
    public static List<Task> MyTask() {
        if (!Schema.SObjectType.Task.fields.subject.isAccessible()){
           
            return NULL;
            
        }
        return [SELECT Id, ActivityDate, Priority, Status, Type, Subject FROM Task WHERE OwnerId = :UserInfo.getUserId() and ActivityDate = NEXT_N_DAYS:7 and IsClosed=false limit 20 ];
    }
    @AuraEnabled
    public static List<Task> TaskByFilter(string fltr) {
        if (!Schema.SObjectType.Task.fields.subject.isAccessible()){
            return NULL;
            
        }
        List <Task> taskList = new List <Task> ();
        
        string query='',whereClause='';
        if(fltr =='AllOpen'){
            whereClause='';
        }else if ( fltr == 'ThisMonth'){
            whereClause='and ActivityDate = THIS_MONTH';
        }
        else if( fltr == 'Overdue'){
            whereClause='and ActivityDate < TODAY';
        }
        else if(fltr == 'Today'){
            whereClause='and ActivityDate = TODAY';
        }
        else if(fltr == 'TodayOverdue'){
            whereClause='and ActivityDate <= TODAY';
            
        }
        else if(fltr == 'Tomorrow'){
            whereClause='and ActivityDate = TOMORROW';
            
        }
        else if(fltr == 'NextSevenDays'){
            whereClause='and (ActivityDate = NEXT_N_DAYS:7 OR ActivityDate = TODAY)';
            
        }else {
            whereClause='and ActivityDate <= NEXT_N_DAYS:7';
        }
        
        query = 'SELECT Id, ActivityDate,Priority,Status,Subject FROM Task WHERE (ownerId = \'' + UserInfo.getUserID() + '\' and IsClosed=false ) '+whereClause+' limit 100';
        taskList = Database.query(query); 
        return taskList;
    }
}
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
When trying to query the CaseId on the SOQL part of the Apex Class it doesn't return anything. I'm sure I did it the wrong way as I'm quite green to Apex and coding. 

Thanks a lot. 

Andreas
Hi all, 

I'm quite new to AMPScript and don't get why the following error occures when trying to preview and test the email the template based Email with a specific DE : 
 error message occuring when Preview and test with a DE
“The subscriber preview failed to generate. Review the details, correct all issues, and try again.
The specified attribute or custom object field name was not found for this client.
Function Call: RetrieveSalesforceObjects('Campaign','Code_CE__c','ID','=',campaignID)
Attribute or Field Name: campaignID”. 

Here is the AMPScript code of the Template-Based Email : 
%%[
    SET @SF_CodeCE = ""
SET @rs = RetrieveSalesforceObjects('Campaign','Code_CE__c','ID','=',campaignID) 
 if rowCount(@RS) == 1 then
      SET @SF_CodeCE= field(row(@rs,1),1)
ELSE 
     SET @SF_CodeCE=" "
ENDIF
 ]%%

What should I modify on the DE so that it will work ? 

Thanks a lot. 
Hi all,
 
I'm looking for a way to populate the sum of Events related to an Account (number of visits), over a period of time, probably fiscal year, and display this field on the Account Layout.
How would I be able to do that ? Roll-up summary, Trigger ? My dev skills are quite limited. 
 
Thanks a lot.
Hi all,
 
I'm looking for a way to populate the sum of Events related to an Account (number of visits), over a period of time, probably fiscal year, and display this field on the Account Layout.
How would I be able to do that ? Roll-up summary, Trigger ? My dev skills are quite limited. 
 
Thanks a lot.

Hi,

 

Can anybody pls tell me how to retrieve list of Tasks for a particular Case using Apex coding.

  • December 29, 2011
  • Like
  • 0