기회 및 해당 기회와 관련된 모든 레코드를 생성해야하는 테스트 메서드를 작성하려고합니다. 가장 이상한 곳에서 널 포인터 예외가 계속 발생합니다. null 포인터 예외가있는 Salesforce Apex 테스트 클래스
public static void createOpp() {
OpportunityEscalationtest.a = new Account(Name = 'SGC Test Account'
, Type = 'Customer'
, Phone = '(00) 0000 0000');
insert OpportunityEscalationtest.a;
OpportunityEscalationtest.c = new List<Contact>();
Contact newC = new Contact(FirstName = 'Jack'
, LastName = 'O\'Neil'
, Phone = '(00) 0000 0000'
, AccountId = OpportunityEscalationtest.a.Id);
OpportunityEscalationtest.c.add(newC);
newC = new Contact(FirstName = 'Samantha'
, LastName = 'Carter'
, Phone = '(00) 0000 0000'
, AccountId = OpportunityEscalationtest.a.Id);
OpportunityEscalationtest.c.add(newC);
newC = new Contact(FirstName = 'Daniel'
, LastName = 'Jackson'
, Phone = '(00) 0000 0000'
, AccountId = OpportunityEscalationtest.a.Id);
OpportunityEscalationtest.c.add(newC);
insert OpportunityEscalationtest.c;
Contact priCont = [Select Id from Contact where FirstName = 'Jack' limit 1];
OpportunityEscalationtest.a.GillForce__Primary_Contact__c = priCont.Id;
OpportunityEscalationtest.o = new Opportunity(Name = 'Mountain Complex Water'
, CloseDate = system.today()
, StageName = 'Business Analysis'
, AccountId = OpportunityEscalationtest.a.Id);
insert OpportunityEscalationtest.o;
for (Contact cont : c) {
OpportunityContactRole role = new OpportunityContactRole(ContactId = cont.Id
, OpportunityId = OpportunityEscalationtest.o.Id
, Role = 'Descision Maker');
role.IsPrimary = (OpportunityEscalationtest.a.GillForce__Primary_Contact__c == cont.Id);
insert role;
}
}
오류
는 이러한 코드 2 선 사이 어딘가에 발생합니다 :insert OpportunityEscalationtest.c;
Contact priCont = [Select Id from Contact where FirstName = 'Jack' limit 1];
나는이 코드 조각 자체에 포함해야 오해 오전 않는 한 비트가 난처한 상황에 빠진입니다. 어떤 아이디어라도 우수 할 것입니다.
이 코드를 테스트 메소드로 실행하고 있습니까?'testMethod public static void createOpp()'? –