You need to sign in to do that
Don't have an account?
uHaveOptions
Test Class... Trying to make it work.
Hello All,
I'm trying to create a test call on Apex Trigger. Kindly help on this test class.
APEX Trigger:
trigger CallDate on Task (after insert, after update, after delete)
{
Set<Id> con_set = new Set<Id>();
List<Contact> con_list = new List<Contact>();
for( Task T: Trigger.new )
{
if(String.valueof(T.whoid).startsWith('003') && T.Status=='Completed' && T.Subject=='Call' )
{
con_set.add(T.whoid);
}
}
for(AggregateResult aggregateResult:[SELECT max(createdDate)MaxCDate,whoid FROM Task WHERE whoid IN: con_set AND Status ='Completed' AND Subject ='Call' Group By whoid])
{
con_list.add(new Contact(Id=(id)aggregateResult.get('whoid'),Last_Call__c=date.valueof(aggregateResult.get('MaxCDate'))));
}
try
{
if(con_list !=null && con_list.size()>0)
{
update con_list;
}
}Catch(Exception e){
system.debug('Exception ***'+e.getMessage());
}
}
TEST CLASS:
@IsTest()
public class CallDateTest
{
static testMethod void MyUnitTest()
{
list<id> con_set = new list<Id>();
List<contact> con_list = new List<contact>();
for( Task T: Trigger.new )
insert con_set;
Task t = new Task(Priority = 'Normal', whoId = task.id, Subject = 'Call', Status = 'Not Started', Call_Result__c = 'Reached');
insert t;
try
{
insert t;
}catch (Exception ee)
{
}
}
}
I'm getting a *"Compile Error: DML requires SObject or SObject list type: List<Id> at line 10 column 8"* Where am I doing this incorrectly?
Thanks
I'm trying to create a test call on Apex Trigger. Kindly help on this test class.
APEX Trigger:
trigger CallDate on Task (after insert, after update, after delete)
{
Set<Id> con_set = new Set<Id>();
List<Contact> con_list = new List<Contact>();
for( Task T: Trigger.new )
{
if(String.valueof(T.whoid).startsWith('003') && T.Status=='Completed' && T.Subject=='Call' )
{
con_set.add(T.whoid);
}
}
for(AggregateResult aggregateResult:[SELECT max(createdDate)MaxCDate,whoid FROM Task WHERE whoid IN: con_set AND Status ='Completed' AND Subject ='Call' Group By whoid])
{
con_list.add(new Contact(Id=(id)aggregateResult.get('whoid'),Last_Call__c=date.valueof(aggregateResult.get('MaxCDate'))));
}
try
{
if(con_list !=null && con_list.size()>0)
{
update con_list;
}
}Catch(Exception e){
system.debug('Exception ***'+e.getMessage());
}
}
TEST CLASS:
@IsTest()
public class CallDateTest
{
static testMethod void MyUnitTest()
{
list<id> con_set = new list<Id>();
List<contact> con_list = new List<contact>();
for( Task T: Trigger.new )
insert con_set;
Task t = new Task(Priority = 'Normal', whoId = task.id, Subject = 'Call', Status = 'Not Started', Call_Result__c = 'Reached');
insert t;
try
{
insert t;
}catch (Exception ee)
{
}
}
}
I'm getting a *"Compile Error: DML requires SObject or SObject list type: List<Id> at line 10 column 8"* Where am I doing this incorrectly?
Thanks
All Answers