You need to sign in to do that
Don't have an account?
test coverage Help
Hi All,
Req: if we update task field under lead , Lead date field get update
Trig:: It works perfectly
trigger TaskAfterInsertUpdate on Task (after update, after insert){
list<Lead> leads = new list<Lead>();
list<id> alliIDs = new list<id>();
datetime myDateTime = datetime.now();
Id taskRecordTypeId = Schema.SObjectType.Task.getRecordTypeInfosByName().get('Old One').getRecordTypeId();
for(Task sTask : trigger.new)
{
if (sTask.WhoId <> NULL && sTask.RecordTypeid == taskRecordTypeId && string.valueOf(sTask.WhoId).startsWith('00Q'))
{
alliIDs.add(sTask.Whoid);
}
}
Map<Id,Lead> leadmap = new Map<Id, Lead>([select Id,BU__c,Last_Date__c,CreatedDate,LeadSource,Country,Status,DonotCall,Mobile__c ,Phone__c from Lead where Id in : alliIDs]);
Map<Id,Lead> allMap = new Map<Id, Lead>();
for(Lead lead : leadmap.Values()){
idcreateddateMap.put(lead.Id,lead);
}
for(Task tsk :Trigger.new){
if (tsk.WhoId <> NULL && tsk.RecordTypeid == taskRecordTypeId && string.valueOf(tsk.WhoId).startsWith('00Q')){
if(allMap .get(tsk.WhoId).CreatedDate.Date().daysBetween(myDateTime.Date())>10& allMap .get(tsk.WhoId).Status <> 'Open' && allMap .get(tsk.WhoId).LeadSource == 'All Data' &&(tsk.Outcome__c == 'Back Me' || tsk.Outcome__c=='ywefuw' || tsk.Outcome__c=='My all' || tsk.Outcome__c == 'Get one') && tsk.Type == 'Out'){
idcreateddateMap.get(tsk.WhoId).Last_Date__c = NULL;
}
leads.add(idcreateddateMap.get(t.WhoId));
}
}
update leads;
}
Test Class:: but it's not cover fully
@isTest
public class TestTaskAfterInsertUpdate
{
static testMethod void TestTaskAfterInsertUpdate()
{
task t = new task(Subject='Call',Type='Outbound Call',Status='Not Started',Priority='Normal');
insert t;
}
}
Try this test class
For record type coverage go through this post of mine.
http://salesforceworld4u.blogspot.in/search/label/Record%20type%20for%20creating%20test%20class%20data%20in%20Apex%20Salesforce