You need to sign in to do that
Don't have an account?
Help with 1st trigger test
It appears that this test doesn't cause the trigger to fire. Please help.
Trigger
trigger CaptureLevel1Owner on Case (before update) {
for(Case c: Trigger.new) {
String caseLevel2 = 'Level 2';
if (Trigger.isUpdate) {
if (c.Level__c == caseLevel2) {
if (c.Level_1_Owner__c == null)
c.Level_1_Owner__c = c.Level_1_Case_Owner_Id__c;
}
}
}
}
Test Class
@isTest
private class TestCaptureLevel1Owner {
static testMethod void testLevelTrigger() {
Case[] myCase = new Case[] {
new Case(Subject = 'Trigger Test', Status = '10-Working',
Level__c = 'Level 1', Level_1_Owner__c = null,
OwnerId = '00580000001Usii', Level_1_Case_Owner_Id__c = '00580000001Usii' ) } ;
insert myCase;
System.assert(myCase[0].Level_1_Owner__c == null);
System.assert(myCase[0].Level__c == 'Level 1');
System.assert(myCase[0].OwnerId == '00580000001Usii');
myCase[0].Level__c = 'Level 2';
// Verify that conditions are set so that trigger will fire
System.assert(myCase[0].Level_1_Owner__c == null);
System.assert(myCase[0].Level__c == 'Level 2');
// and that the Level 1 Owner ID is not empty so there is something for the trigger to load
System.assert(myCase[0].Level_1_Case_Owner_Id__c != null);
update myCase;
// This should fail since the trigger should have loaded Level 1 Owner,
// but it doesn't which implies that the trigger isn't firing
System.assert(myCase[0].Level_1_Owner__c == null);
// System.assertEquals(c.Level_1_Owner__c,c.Level_1_Case_Owner_Id__c);
// System.assert(c.Level_1_Owner__c == c.Level_1_Case_Owner_Id__c);
}
}
You'll need to retrieve Level_1_Owner before you can check its value. The new value isn't automatically returned just because you updated the sObject variable. So:
Case changedCase = [SELECT Level_1_Owner FROM Case WHERE id=: myCase[0].id LIMIT 1];
System.assert(changedCase.Level_1_Owner==null); //should faile as expected
SFDC doesn't transmit any data unless you ask for it (except for Id), even for the sObject variables you're using.
All Answers
You'll need to retrieve Level_1_Owner before you can check its value. The new value isn't automatically returned just because you updated the sObject variable. So:
Case changedCase = [SELECT Level_1_Owner FROM Case WHERE id=: myCase[0].id LIMIT 1];
System.assert(changedCase.Level_1_Owner==null); //should faile as expected
SFDC doesn't transmit any data unless you ask for it (except for Id), even for the sObject variables you're using.
worked great thanks