• Robert Haines
  • NEWBIE
  • 20 Points
  • Member since 2016

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 9
    Replies
This trigger is designed to count activities on a lead, like # of calls, # of emails, etc. The code works well, but I can't for the life of me seem to be able to create a test class that gets sufficient code coverage. I get like 9% code coverage by creating a lead and creating a task in my test code. PLEASE SHOW ME HOW IT'S DONE if you would, please. 

trigger FS_CountActivitiesOL on Lead (before update) 
{
    for(Lead lead : trigger.new) 
    {
        
        id thisLeadID = lead.id;
        
        List<Task> tasklist = [SELECT Type, CallDurationInSeconds, ActivityDate, FS_Connect__c From Task WHERE IsClosed = True AND whoid = :thisLeadID ORDER BY ActivityDate ASC];    
        
        if (tasklist.size() > 0) {
            
            //Let's add up all the tasks
            integer i = 0;
            for(Task t : tasklist){
                i++;
            }
            lead.FS_Activity_Count__c = i;
            
            //Let's find the ACTIVITIES BEFORE FIRST CONNECT, EMAILS BEFORE FIRST CONNECT, CALLS BEFORE FIRST CONNECT, FIRST CONNECT DATE and FIRST CONNECT DURATION (IN SEC)
            integer abfc = 0; 
            integer ebfc = 0; 
            integer cbfc = 0; 
            for(Task t : tasklist){
               if (t.FS_Connect__c == FALSE) {
                   abfc++;
                   if (t.Type == 'Call') {
                       cbfc++;
                   }
                   ELSE IF (t.Type == 'Email') {
                       ebfc++;
                   }
               }
               Else {
                   if (t.Type == 'Call') {
                       cbfc++;
                   }
                   ELSE IF (t.Type == 'Email') {
                       ebfc++;
                   }
                   lead.FS_First_Connect_Date__c = t.ActivityDate;
                   lead.FS_First_Connect_Duration_Sec__c = t.CallDurationInSeconds;
                   abfc++;
                   break;
               }
            }
            lead.FS_Activities_Before_First_Connect__c = abfc;
            lead.FS_Calls_Before_First_Connect__c = cbfc;
            lead.FS_Emails_Before_First_Connect__c = ebfc;
            
            //Now let's get the FIST CALL DATE
            for(Task t : tasklist){
               if (t.Type == 'Call') {
                   lead.FS_First_Call_Date__c = t.ActivityDate;
                   break;
               }
            }
            
            //Now let's get the FIRST EMAIL DATE
            for(Task t : tasklist){
               if (t.Type == 'Email') {
                   lead.FS_First_Email_Date__c = t.ActivityDate;
                   break;
               }
            }
            
            //Now let's get the TOTAL # OF CALLS, TOTAL # OF EMAILS and TOTAL # OF CONNECTS
            integer tncalls = 0; 
            integer tnemails = 0; 
            integer tnconns = 0;         
            for(Task t : tasklist){
               IF (t.Type == 'Email') {
                   tnemails++;
               }
               ELSE IF (t.Type == 'Call') {
                   tncalls++;
               }
               IF (t.FS_Connect__c == TRUE) {
                   tnconns++;
               }
            }    
            lead.FS_Total_Number_of_Calls__c = tncalls;
            lead.FS_Total_Number_of_Emails__c = tnemails;
            lead.FS_Total_Number_of_Connects__c = tnconns;   

        }     
    }
}
Community, I hope you can help me. I'm stumped. 

I'm the Salesforce admin at our company and I have created a dashboard full of reports with the interntion of packaging that all up and sharing it with our customers. However, once I have packaged up the dashboard, reports and custom fields assciated with the reports, I tested this package first by installing it into another Salesforce account, but the reports do not work... at all.

Just to give you more information, here is the dashboard in our primary SFDC account (which works perfectly)... 
User-added image

On an individual report level, I use Joined Reports and the "assigned" field as the cross-block grouping field...
User-added image

However, once I have installed the package in another SFDC account (which is essentially a mirror of our main account), the dashboard is blank...
User-added image

... and my reports are now MISSING the "assigned" grouping field...
User-added image

I can't even add the "assigned" field back in... it's actually there, it's just invisible and completely inaccessible. I know it's there because when I edit my chart, it still shows "assigned" as the Y-axis...
User-added image

But it's straight-up NOT working. 

PLEASE help :-) 
This trigger is designed to count activities on a lead, like # of calls, # of emails, etc. The code works well, but I can't for the life of me seem to be able to create a test class that gets sufficient code coverage. I get like 9% code coverage by creating a lead and creating a task in my test code. PLEASE SHOW ME HOW IT'S DONE if you would, please. 

trigger FS_CountActivitiesOL on Lead (before update) 
{
    for(Lead lead : trigger.new) 
    {
        
        id thisLeadID = lead.id;
        
        List<Task> tasklist = [SELECT Type, CallDurationInSeconds, ActivityDate, FS_Connect__c From Task WHERE IsClosed = True AND whoid = :thisLeadID ORDER BY ActivityDate ASC];    
        
        if (tasklist.size() > 0) {
            
            //Let's add up all the tasks
            integer i = 0;
            for(Task t : tasklist){
                i++;
            }
            lead.FS_Activity_Count__c = i;
            
            //Let's find the ACTIVITIES BEFORE FIRST CONNECT, EMAILS BEFORE FIRST CONNECT, CALLS BEFORE FIRST CONNECT, FIRST CONNECT DATE and FIRST CONNECT DURATION (IN SEC)
            integer abfc = 0; 
            integer ebfc = 0; 
            integer cbfc = 0; 
            for(Task t : tasklist){
               if (t.FS_Connect__c == FALSE) {
                   abfc++;
                   if (t.Type == 'Call') {
                       cbfc++;
                   }
                   ELSE IF (t.Type == 'Email') {
                       ebfc++;
                   }
               }
               Else {
                   if (t.Type == 'Call') {
                       cbfc++;
                   }
                   ELSE IF (t.Type == 'Email') {
                       ebfc++;
                   }
                   lead.FS_First_Connect_Date__c = t.ActivityDate;
                   lead.FS_First_Connect_Duration_Sec__c = t.CallDurationInSeconds;
                   abfc++;
                   break;
               }
            }
            lead.FS_Activities_Before_First_Connect__c = abfc;
            lead.FS_Calls_Before_First_Connect__c = cbfc;
            lead.FS_Emails_Before_First_Connect__c = ebfc;
            
            //Now let's get the FIST CALL DATE
            for(Task t : tasklist){
               if (t.Type == 'Call') {
                   lead.FS_First_Call_Date__c = t.ActivityDate;
                   break;
               }
            }
            
            //Now let's get the FIRST EMAIL DATE
            for(Task t : tasklist){
               if (t.Type == 'Email') {
                   lead.FS_First_Email_Date__c = t.ActivityDate;
                   break;
               }
            }
            
            //Now let's get the TOTAL # OF CALLS, TOTAL # OF EMAILS and TOTAL # OF CONNECTS
            integer tncalls = 0; 
            integer tnemails = 0; 
            integer tnconns = 0;         
            for(Task t : tasklist){
               IF (t.Type == 'Email') {
                   tnemails++;
               }
               ELSE IF (t.Type == 'Call') {
                   tncalls++;
               }
               IF (t.FS_Connect__c == TRUE) {
                   tnconns++;
               }
            }    
            lead.FS_Total_Number_of_Calls__c = tncalls;
            lead.FS_Total_Number_of_Emails__c = tnemails;
            lead.FS_Total_Number_of_Connects__c = tnconns;   

        }     
    }
}