+ Start a Discussion
Jeevana Priyanka BJeevana Priyanka B 

How i get code coverage for below if condition

Task[] restoreTaskOwner = new Task[0];
for(Task task : [SELECT Id, OwnerId, CustonField__c FROM Task Where WhatId IN :changedOwnerIds AND IsClosed = FALSE AND CustonField__c<> null]){
if (task.OwnerId <> tak.CustonField__c) {
                task.OwnerId = task.CustonField__c;
                restoreTaskOwner.add(tsk); } }
Angel Robles MAngel Robles M
If this code is executed by a trigger, just make sure that the user id in the CustomField__c is different from the user that created the task record.
Hi Jeevana,
Use this in your test class:
User u = new User(
     ProfileId = USERINFO.getProfileId(),
     LastName = 'last',
     Email = 'testusr@userinfo.com',
     Username = 'testusr@userinfo.com' + System.currentTimeMillis(),
     CompanyName = 'TEST',
     Title = 'title',
     Alias = 'alias',
     TimeZoneSidKey = 'America/Los_Angeles',
     EmailEncodingKey = 'UTF-8',
     LanguageLocaleKey = 'en_US',
     LocaleSidKey = 'en_US'
insert u;
task tsk = new task();
tsk.Subject='test subject';
//other required fields
insert tsk;

Mark as best if it works.