function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
NarcissuNarcissu 

Need Help for Test Coverage Code

Hi,

 

I just finished the code below. It works fine as my expect but I have a hard time writing the test code. Can anyone please have a look at it and help me write the test code? Thanks in advance.

 

trigger UpdateUpcoming on Task (after insert, after update)
{
    Set<id> AccountIDs = new set<id>();
    list<Account> AcctList = new list<Account>();
    for(task c : Trigger.new)
    {
        for(Account at:[Select id,upcoming_due__c From Account where id =: c.accountid])
        {
            if (date.valueof(c.ActivityDate) == null)
                at.upcoming_due__c = null;
            else
            if (at.upcoming_due__c == null)
                at.upcoming_due__c = date.valueof(c.ActivityDate);
            if (date.valueof(c.ActivityDate) < at.upcoming_due__c)
                at.upcoming_due__c = date.valueof(c.ActivityDate);
            else
                at.upcoming_due__c = at.upcoming_due__c;
            AcctList.add(at);
        }
    }
    update AcctList;
}

NarcissuNarcissu

I am sorry, but ignore the line:

 

if (date.valueof(c.ActivityDate) == null)
                at.upcoming_due__c = null;
            else

Rolando EstevesRolando Esteves

Can you post the @isTest class you have.

NarcissuNarcissu

Thanks for your reply, here is the test I have, but does handle the "IF" section.

 

@isTest
private class testUpdateUpcomingTest0
{
public static testMethod void unitTestinsert_Contact_Activity4Task()
{
account ac=new account(name='test');
insert ac;
case c=new case(status='abc',accountid=ac.id);
insert c;
}
}

Rolando EstevesRolando Esteves

You should create a task also.