You need to sign in to do that
Don't have an account?
cml9
Need help in creating test class
trigger CasesNewCallLog on Task (after insert) {
list <case> c = new list <case>();
for (Task t:trigger.new){
if(t.WhatId.getSobjectType() == case.SObjectType){
if(t.subject == 'Call') {
c.add(new case(id=t.whatid,Last_Comment_Date__c=System.now()
));
}
}
}
if(c!=null){
update c;
}
}
==================
I have created 1 but its not working
@isTest
class UpdateLastCaseComment {
public static testMethod void caseUpdateLastActivity() {
User u = new User();
u.FirstName = 'You';
u.LastName = 'Mei';
u.Alias = 'youmei';
u.Username = 'youmei@test.com';
u.Id = '0051a000000Ho3g';
u.LocaleSidKey = 'en_AU';
u.EmailEncodingKey = 'ISO-8859-1';
u.TimeZoneSidKey = 'Asia/Singapore';
u.Email='youmei@test.com';
insert u;
Case c = new Case();
c.Status = 'New';
c.Origin = 'Phone';
c.GSOT_Role__c = 'Staff';
insert c;
Task t = new Task();
t.OwnerId = u.id;
t.Subject = 'Anything';
t.Priority = 'Normal';
t.WhatId = c.id;
insert t;
}
}
BUT ITS NOT WORKING and I DONT KNOW ANYMORE!
list <case> c = new list <case>();
for (Task t:trigger.new){
if(t.WhatId.getSobjectType() == case.SObjectType){
if(t.subject == 'Call') {
c.add(new case(id=t.whatid,Last_Comment_Date__c=System.now()
));
}
}
}
if(c!=null){
update c;
}
}
==================
I have created 1 but its not working
@isTest
class UpdateLastCaseComment {
public static testMethod void caseUpdateLastActivity() {
User u = new User();
u.FirstName = 'You';
u.LastName = 'Mei';
u.Alias = 'youmei';
u.Username = 'youmei@test.com';
u.Id = '0051a000000Ho3g';
u.LocaleSidKey = 'en_AU';
u.EmailEncodingKey = 'ISO-8859-1';
u.TimeZoneSidKey = 'Asia/Singapore';
u.Email='youmei@test.com';
insert u;
Case c = new Case();
c.Status = 'New';
c.Origin = 'Phone';
c.GSOT_Role__c = 'Staff';
insert c;
Task t = new Task();
t.OwnerId = u.id;
t.Subject = 'Anything';
t.Priority = 'Normal';
t.WhatId = c.id;
insert t;
}
}
BUT ITS NOT WORKING and I DONT KNOW ANYMORE!