You need to sign in to do that
Don't have an account?
Admin 123
trigger UpdateSA on Task (before insert,before update) { for(Task t: Trigger.new) { If (t.Date_Time_Denied__c == null || t.Declined_By__c == null) { t.SA_Denied__c = true; } else { t.SA_Denied__c = false; }}
trigger UpdateSA on Task (before insert,before update)
{ for(Task t: Trigger.new)
{ If (t.Date_Time_Denied__c == null || t.Declined_By__c == null)
{
t.SA_Denied__c = true;
} else
{
t.SA_Denied__c = false;
}
}
Test class for this?
{ for(Task t: Trigger.new)
{ If (t.Date_Time_Denied__c == null || t.Declined_By__c == null)
{
t.SA_Denied__c = true;
} else
{
t.SA_Denied__c = false;
}
}
Test class for this?
Please try below test class and let me know the code coverage:
@isTest
private class testMyTaskTrigger {
public static testMethod void testTTrigger1(){
Task t = new Task();
t.OwnerId = UserInfo.getUserId();
t.Subject='Testing';
t.Status='Not Started';
t.Priority='Normal';
t.Date_Time_Denied__c= System.Now();
insert t;
}
public static testMethod void testTTrigger2(){
Task t1 = new Task();
t1.OwnerId = UserInfo.getUserId();
t1.Subject='t=Testing';
t1.Status='Not Started';
t1.Priority='Normal';
insert t1;
}}
All Answers
It's very simple, Create a method and insert a task record in which your "Date_Time_Denied__c" field will be null and and in second method your "Date_Time_Denied__c" will not be null.
Create one another method which ll check the null pointer exception case for Salesforce best practice of test classes.
Please check the below code..
Please let me know if this help !
Thanks
Shivdeep
Please try below test class and let me know the code coverage:
@isTest
private class testMyTaskTrigger {
public static testMethod void testTTrigger1(){
Task t = new Task();
t.OwnerId = UserInfo.getUserId();
t.Subject='Testing';
t.Status='Not Started';
t.Priority='Normal';
t.Date_Time_Denied__c= System.Now();
insert t;
}
public static testMethod void testTTrigger2(){
Task t1 = new Task();
t1.OwnerId = UserInfo.getUserId();
t1.Subject='t=Testing';
t1.Status='Not Started';
t1.Priority='Normal';
insert t1;
}}