• JimmyATL
  • NEWBIE
  • 0 Points
  • Member since 2011

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 7
    Replies

Hi All,

 

I'm new here, so hopefully I don't say anything too silly/dumb.

 

I am having a problem with testing an undelete trigger I have written.  I am getting an DMLException for de-referenfing a null object when trying to test my undelete trigger.  It may be that I am misunderstanding completely how testing of Apex undeletes should work... 

 

My basic requirements are that I have an order, and I have a field on that order called Needs Attn.  I need to set this field to True whenever the order is updated or when it is undeleted.  

 

My Trigger in JGOrderUpdate.trigger:

 

trigger JGOrderUpdate on JG__Order__c (before update, after undelete) {
	    for(JG__Order__c o : Trigger.new) {
		    JG__Order__c old = Trigger.oldMap.get(o.Id);
		    if(!old.Needs_Attn__c) o.Needs_Attn__c = true;
		}
	}

 

My Test Code JGTriggerTests.cls :

 

    // create a order
    JG__Order__c o = new JG__Order__c();
    o.Needs_Attn__c = false;
    insert o;

    // this kicks off the before update trigger for orders
    update o;

     // Confirms Actual update tests for orders
     JG__Order__c test_o = [Select Id, Needs_Attn__c From JG__Order__c Where Id =: o.Id];
     System.assert(test_o.Needs_Attn__c);

     // now we set the order back to needing attention false
     o.Needs_Attn__c = false;
	
     // now we delete the order so we can undelete it to make sure when we undelete it actually
     // changes to Needs_Attn__c == True
     delete o;
	
     // this kicks off the undelete trigger code
     // HAVING THE PROBLEM ON THE LINE BELOW
     undelete o;

     // did the trigger run properly
     System.assert(test_so.Needs_Attn__c);

 

 

Here's the error i get on the line above with "undelete o;"

 

 

Description Resource Path Location Type
 System.DmlException: Undelete failed. 
 first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, JGOrderUpdate: execution of AfterUndelete
 caused by: System.NullPointerException: Attempt to de-reference a null object
 Trigger.JGOrderUpdate: line 3, column 38: [] JGTriggerTests.cls
 Description Resource Path Location TypeSystem.DmlException: Undelete failed.  
 first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, JGOrderUpdate: execution of AfterUndelete
 caused by: System.NullPointerException: Attempt to de-reference a null object
 Trigger.JGOrderUpdate: line 3, column 38: [] JGTriggerTests.cls

Description Resource Path Location Type System.DmlException: Undelete failed.  first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, JGOrderUpdate: execution of AfterUndelete caused by: System.NullPointerException: Attempt to de-reference a null object Trigger.JGOrderUpdate: line 3, column 38: [] JGTriggerTests.cls Description Resource Path Location TypeSystem.DmlException: Undelete failed.   first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, JGOrderUpdate: execution of AfterUndelete caused by: System.NullPointerException: Attempt to de-reference a null object Trigger.JGOrderUpdate: line 3, column 38: [] JGTriggerTests.cls

 

 

 

Any help would be greatly appreciated!

 

Thanks
j

Hi All,

 

I'm new here, so hopefully I don't say anything too silly/dumb.

 

I am having a problem with testing an undelete trigger I have written.  I am getting an DMLException for de-referenfing a null object when trying to test my undelete trigger.  It may be that I am misunderstanding completely how testing of Apex undeletes should work... 

 

My basic requirements are that I have an order, and I have a field on that order called Needs Attn.  I need to set this field to True whenever the order is updated or when it is undeleted.  

 

My Trigger in JGOrderUpdate.trigger:

 

trigger JGOrderUpdate on JG__Order__c (before update, after undelete) {
	    for(JG__Order__c o : Trigger.new) {
		    JG__Order__c old = Trigger.oldMap.get(o.Id);
		    if(!old.Needs_Attn__c) o.Needs_Attn__c = true;
		}
	}

 

My Test Code JGTriggerTests.cls :

 

    // create a order
    JG__Order__c o = new JG__Order__c();
    o.Needs_Attn__c = false;
    insert o;

    // this kicks off the before update trigger for orders
    update o;

     // Confirms Actual update tests for orders
     JG__Order__c test_o = [Select Id, Needs_Attn__c From JG__Order__c Where Id =: o.Id];
     System.assert(test_o.Needs_Attn__c);

     // now we set the order back to needing attention false
     o.Needs_Attn__c = false;
	
     // now we delete the order so we can undelete it to make sure when we undelete it actually
     // changes to Needs_Attn__c == True
     delete o;
	
     // this kicks off the undelete trigger code
     // HAVING THE PROBLEM ON THE LINE BELOW
     undelete o;

     // did the trigger run properly
     System.assert(test_so.Needs_Attn__c);

 

 

Here's the error i get on the line above with "undelete o;"

 

 

Description Resource Path Location Type
 System.DmlException: Undelete failed. 
 first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, JGOrderUpdate: execution of AfterUndelete
 caused by: System.NullPointerException: Attempt to de-reference a null object
 Trigger.JGOrderUpdate: line 3, column 38: [] JGTriggerTests.cls
 Description Resource Path Location TypeSystem.DmlException: Undelete failed.  
 first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, JGOrderUpdate: execution of AfterUndelete
 caused by: System.NullPointerException: Attempt to de-reference a null object
 Trigger.JGOrderUpdate: line 3, column 38: [] JGTriggerTests.cls

Description Resource Path Location Type System.DmlException: Undelete failed.  first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, JGOrderUpdate: execution of AfterUndelete caused by: System.NullPointerException: Attempt to de-reference a null object Trigger.JGOrderUpdate: line 3, column 38: [] JGTriggerTests.cls Description Resource Path Location TypeSystem.DmlException: Undelete failed.   first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, JGOrderUpdate: execution of AfterUndelete caused by: System.NullPointerException: Attempt to de-reference a null object Trigger.JGOrderUpdate: line 3, column 38: [] JGTriggerTests.cls

 

 

 

Any help would be greatly appreciated!

 

Thanks
j