You need to sign in to do that
Don't have an account?

error in test class please suggest me
Hi
I got below error and i have given trigger and also test class , could you please suggets me
System.DmlException: Update failed. First exception on row 0 with id a0i4E000000t7jmQAA; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, cus: execution of AfterUpdate
caused by: System.NullPointerException: Argument cannot be null
Trigger.cus: line 10, column 1: []
Stack Trace Class.Testcus.testingCus: line 40, column 1
trigger
trigger cus on Sample_Transaction__c(after update) {
Call2__c Objopp;
Map<Id,Sample_Transaction__c> o = new Map<Id,Sample_Transaction__c>();
o = trigger.oldMap;
for (Sample_Transaction__c objCustomer: Trigger.new) {
if (objCustomer.Status__c== 'Active') {
if(objCustomer.Status__c!= o.get(objCustomer.Id).Status__c) {
List<String> s = new List<String>{objCustomer.Call_ID__c};
ApexPages.StandardController controller = new ApexPages.standardController(Objopp);
UnlockRecordDuringApprovalCon ObjUnlock= new UnlockRecordDuringApprovalCon(controller);
for(Call2__c c: [SELECT id FROM Call2__c WHERE Name IN :s]){
ObjUnlock.processRecord(c.id );
}
}
}
}
}
test class
@isTest
private class Testcus {
static testMethod void testingCus(){
Account TestOpp=new Account();
TestOpp.Name='Testopp1';
TestOpp.SLN__c='asdfc45';
insert TestOpp;
Call2__c Testcall =new Call2__c();
Testcall.Account__c=TestOpp.id;
insert Testcall ;
Address__c testadd = new Address__c();
testadd.Name='aaa';
testadd.Account__c=TestOpp.id;
insert testadd;
Sample_Lot__c testsample=new Sample_Lot__c();
testsample.Name='aaa';
insert testsample;
Product__c testprod = new Product__c();
testprod.Name='aaa';
insert testprod;
Sample_Transaction__c testapp1 = new Sample_Transaction__c();
testapp1.Account_ID__c =TestOpp.id;
testapp1.Address_ID__c= testadd.id;
testapp1.Sample_Lot_ID__c=testsample.id;
testapp1.Product__c= testprod.id;
insert testapp1;
testapp1.Status__c = 'Saved';
update testapp1 ;
}
}
I got below error and i have given trigger and also test class , could you please suggets me
System.DmlException: Update failed. First exception on row 0 with id a0i4E000000t7jmQAA; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, cus: execution of AfterUpdate
caused by: System.NullPointerException: Argument cannot be null
Trigger.cus: line 10, column 1: []
Stack Trace Class.Testcus.testingCus: line 40, column 1
trigger
trigger cus on Sample_Transaction__c(after update) {
Call2__c Objopp;
Map<Id,Sample_Transaction__c> o = new Map<Id,Sample_Transaction__c>();
o = trigger.oldMap;
for (Sample_Transaction__c objCustomer: Trigger.new) {
if (objCustomer.Status__c== 'Active') {
if(objCustomer.Status__c!= o.get(objCustomer.Id).Status__c) {
List<String> s = new List<String>{objCustomer.Call_ID__c};
ApexPages.StandardController controller = new ApexPages.standardController(Objopp);
UnlockRecordDuringApprovalCon ObjUnlock= new UnlockRecordDuringApprovalCon(controller);
for(Call2__c c: [SELECT id FROM Call2__c WHERE Name IN :s]){
ObjUnlock.processRecord(c.id );
}
}
}
}
}
test class
@isTest
private class Testcus {
static testMethod void testingCus(){
Account TestOpp=new Account();
TestOpp.Name='Testopp1';
TestOpp.SLN__c='asdfc45';
insert TestOpp;
Call2__c Testcall =new Call2__c();
Testcall.Account__c=TestOpp.id;
insert Testcall ;
Address__c testadd = new Address__c();
testadd.Name='aaa';
testadd.Account__c=TestOpp.id;
insert testadd;
Sample_Lot__c testsample=new Sample_Lot__c();
testsample.Name='aaa';
insert testsample;
Product__c testprod = new Product__c();
testprod.Name='aaa';
insert testprod;
Sample_Transaction__c testapp1 = new Sample_Transaction__c();
testapp1.Account_ID__c =TestOpp.id;
testapp1.Address_ID__c= testadd.id;
testapp1.Sample_Lot_ID__c=testsample.id;
testapp1.Product__c= testprod.id;
insert testapp1;
testapp1.Status__c = 'Saved';
update testapp1 ;
}
}
In this line ApexPages.StandardController controller = new ApexPages.standardController(Objopp);
You are passing "Objopp" which is null in the trigger .
Please correct this.
-thanks
Ashlekh Gera
Can you please post your "UnlockRecordDuringApprovalCon " page code so that i can check that you need stadardcontroller (ApexPages.StandardController controller = new ApexPages.standardController(Objopp);) this line or not..
Thanks
karthik