You need to sign in to do that
Don't have an account?
darreln
test class help - task trigger
Hello,
I have received great help with a trigger that displays a warning message when the "public" checkbox is not checked on the creation of a new task with a specific record type (contact object). Upon trying to deploy this, I ran in to the "No code coverage" message, and subsquently learned that a test class mus be written and the trigger must be tested before a deployment is possible.
I am not a programmer, really not sure how I would tackle this. I am hopeful that someone here can help me with a test class for this trigger? I would really apprecaite it! Trigger follows:
trigger PublicFORBRYANTHC on Task (after insert,after Update) {
Set<Id> ids=new Set<Id>();
Set<Id> Conids=new Set<Id>();
for(Task t:trigger.new){
ids.add(t.id);
if(t.WhoId != null && (((String)t.WhoId).substring(0,3) == '003') ) {
conIds.add(t.WhoId);
}
}
List<Contact> con=[Select id from contact where id in:conIds and RecordTypeId in (SELECT Id FROM RecordType WHERE Name = 'Bryant HC')];
for(Task t:trigger.new){
if(t.IsVisibleInSelfService<> true && con.size()>0 ) {
t.AddError('Public Checkbox must be checked!');
}
}
}
I have received great help with a trigger that displays a warning message when the "public" checkbox is not checked on the creation of a new task with a specific record type (contact object). Upon trying to deploy this, I ran in to the "No code coverage" message, and subsquently learned that a test class mus be written and the trigger must be tested before a deployment is possible.
I am not a programmer, really not sure how I would tackle this. I am hopeful that someone here can help me with a test class for this trigger? I would really apprecaite it! Trigger follows:
trigger PublicFORBRYANTHC on Task (after insert,after Update) {
Set<Id> ids=new Set<Id>();
Set<Id> Conids=new Set<Id>();
for(Task t:trigger.new){
ids.add(t.id);
if(t.WhoId != null && (((String)t.WhoId).substring(0,3) == '003') ) {
conIds.add(t.WhoId);
}
}
List<Contact> con=[Select id from contact where id in:conIds and RecordTypeId in (SELECT Id FROM RecordType WHERE Name = 'Bryant HC')];
for(Task t:trigger.new){
if(t.IsVisibleInSelfService<> true && con.size()>0 ) {
t.AddError('Public Checkbox must be checked!');
}
}
}
Test class like below
Let us know if this will help you
All Answers
This is not tested of course so let me know if you get any errors. you may need to adjust the test data to include any required fields.
Test class like below
Let us know if this will help you