• ethan li
  • NEWBIE
  • 0 Points
  • Member since 2012

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 1
    Replies

I have a trigger on task which basically checks the Task's call type and update fields on the corresponding account accordingly. (I omitted some parts since the test is only on the insert part)

 

trigger callType on Task (after insert, after update, after delete) {
    Account[] oa; 
    Account a;
    if(Trigger.IsDelete) { ... } 
else if(Trigger.IsUpdate) { ... } else if(Trigger.IsInsert) { for (Task t : Trigger.new) { oa = [SELECT Id, KYC_Completed__c, Check_in_Scheduled__c FROM Account where Id =:t.WhatId LIMIT 1]; //finds the account task is related to if(oa.size()>0){ a = oa[0]; }else return; //oa.size zero, the task is not related to account. abort mission. //if new trigger is check in or kyc call then respective fields should be true. if (t.Call_Type_aD__c == 'KYC Call') a.KYC_Completed__c = true; else if(t.Call_Type_aD__c == 'Check in') a.Check_in_Scheduled__c = true; else return; } } }

This is the (unfinished) test 

 

@isTest
private class callTypetest{
    static testMethod void testcallType() {
        callTypetest ctt = new callTypetest();
        //Make a new account
        Account a= new Account(
            Name = 'Test Account'
        );
        insert a;
        Task t = new Task(Call_Type_aD__c = 'KYC Call', WhatId = a.Id);
        insert t;
        update a;
        a = [SELECT Id, KYC_Completed__c FROM Account WHERE Id =: a.Id LIMIT 1];
        System.assertEquals(true, a.KYC_Completed__c);

    }

}

 Now my test is simple: when I make the task, the insert part of the trigger is activated (code coverage shows this when I check it). It should tick the KYC_Completed__c to true since the Call_Type_aD__c is KYC Call, and in fact that part of the code ran as shown by the code coverage. I've also updated the account as well as querying it again before the assertEquals. However the assertEquals says expect true, got false.

 

Any help is greatly appreciated!

Thanks in advance.

I have a trigger on task which basically checks the Task's call type and update fields on the corresponding account accordingly. (I omitted some parts since the test is only on the insert part)

 

trigger callType on Task (after insert, after update, after delete) {
    Account[] oa; 
    Account a;
    if(Trigger.IsDelete) { ... } 
else if(Trigger.IsUpdate) { ... } else if(Trigger.IsInsert) { for (Task t : Trigger.new) { oa = [SELECT Id, KYC_Completed__c, Check_in_Scheduled__c FROM Account where Id =:t.WhatId LIMIT 1]; //finds the account task is related to if(oa.size()>0){ a = oa[0]; }else return; //oa.size zero, the task is not related to account. abort mission. //if new trigger is check in or kyc call then respective fields should be true. if (t.Call_Type_aD__c == 'KYC Call') a.KYC_Completed__c = true; else if(t.Call_Type_aD__c == 'Check in') a.Check_in_Scheduled__c = true; else return; } } }

This is the (unfinished) test 

 

@isTest
private class callTypetest{
    static testMethod void testcallType() {
        callTypetest ctt = new callTypetest();
        //Make a new account
        Account a= new Account(
            Name = 'Test Account'
        );
        insert a;
        Task t = new Task(Call_Type_aD__c = 'KYC Call', WhatId = a.Id);
        insert t;
        update a;
        a = [SELECT Id, KYC_Completed__c FROM Account WHERE Id =: a.Id LIMIT 1];
        System.assertEquals(true, a.KYC_Completed__c);

    }

}

 Now my test is simple: when I make the task, the insert part of the trigger is activated (code coverage shows this when I check it). It should tick the KYC_Completed__c to true since the Call_Type_aD__c is KYC Call, and in fact that part of the code ran as shown by the code coverage. I've also updated the account as well as querying it again before the assertEquals. However the assertEquals says expect true, got false.

 

Any help is greatly appreciated!

Thanks in advance.