You need to sign in to do that
Don't have an account?
trigger test coverage- struggling
i hv a child record updating parent reocrd trigger .
trigger is :
trigger childtrigger on child ( before insert )
{
child__c c = Trigger.new[0];
parentobject p=[Select Id,Assigned__c from parent__c where Id=:c.Request__c ];
p.Assigned__c = c.Assigned__c;
update p;
}
i m struggling to write test coverage for it .
approach to test covage.
create a child for existing parent in the sandbox ; and assign the value and update the update in parent; is that approach .
my test failour says it is System.NullPointerException: Attempt to de-reference a null objectClass.crr.Assignedupdate_Test: line 30, column 5 External entry point
Hey
Try this,
parentobject p = new parentObject();
insert p;
child__c c = new child__c(Request__c=p.id);
insert c;
Cheers,
Wes
All Answers
Hey
Try this,
parentobject p = new parentObject();
insert p;
child__c c = new child__c(Request__c=p.id);
insert c;
Cheers,
Wes
first thanks so much for your response.
so you mean above code i will use in test method
Yeah that's right:) The reason you're getting an error is because your test code is trying to do the following:
insert child object;
fire before insert trigger(no parent object exists so an error is thrown).
insert parent object; // we don't get here because of previous error
So all you have to do is shuffle the order of your test code.
Wes