You need to sign in to do that
Don't have an account?
Sony PSP
Test Class for delete
Hi Guys,
good day!
Just a newbie in here, can you assist me with below Apex Class I already made a Test Class and my Problem in the Test Class is the part of method deleteOppContRole() wherein it doesn't covered any help please ?
public class OpportunityContactRoleController {
public Id contRoleId {get; set;}
public Id oppId;
public Opportunity oppObj;
public ApexPages.StandardController controller {get; set;}
public List<OpportunityContactRole> oppContRoles {get; set;}
public OpportunityContactRoleController(ApexPages.StandardController controller){
this.oppObj = (Opportunity)controller.getRecord();
oppId = this.oppObj.Id;
oppContRoles = [SELECT Id,OpportunityId, Contact.Name, Contact.Email, Role, Contact.Account.Name, Contact.Phone, IsPrimary
FROM OpportunityContactRole WHERE OpportunityId = :((Opportunity)controller.getRecord()).Id];
}
public void deleteOppContRole(){
if(contRoleId != null){
OpportunityContactRole ocr = new OpportunityContactRole();
ocr.Id = contRoleId;
delete ocr;
oppContRoles = new List<OpportunityContactRole>();
oppContRoles = [SELECT Id,OpportunityId, Contact.Name, Contact.Email, Role, Contact.Account.Name, Contact.Phone, IsPrimary
FROM OpportunityContactRole WHERE OpportunityId = :((Opportunity)controller.getRecord()).Id];
}
}
public pageReference primaryContact() {
PageReference pageRef = Page.OpportunityPrimaryContact;
pageRef.getParameters().put('Id', oppId);
pageRef.setRedirect(true);
return pageRef;
}
}
Test Class:
@isTest
public class OpportunityContactRoleController_Test {
private static testMethod void testData(){
Account testAccount = new Account(Name = 'Test Account', Country__c = 'US');
insert testAccount;
Contact testContact = new Contact(LastName = 'Test LastName', FirstName = 'Test LastName');
insert testContact;
Opportunity testOpportunity = new Opportunity(AccountId = testAccount.Id, Name = 'Test Opportunity', Country__c = 'US',
CurrencyIsoCode = 'USD', StageName = 'Loan Current', CloseDate = date.today(), Days_In_Term__c = 2 );
insert testOpportunity;
OpportunityContactRoleController controller = new OpportunityContactRoleController(new ApexPages.StandardController(testOpportunity));
OpportunityContactRole ocr = new OpportunityContactRole();
controller.deleteOppContRole();
controller.primaryContact();
}
}
good day!
Just a newbie in here, can you assist me with below Apex Class I already made a Test Class and my Problem in the Test Class is the part of method deleteOppContRole() wherein it doesn't covered any help please ?
public class OpportunityContactRoleController {
public Id contRoleId {get; set;}
public Id oppId;
public Opportunity oppObj;
public ApexPages.StandardController controller {get; set;}
public List<OpportunityContactRole> oppContRoles {get; set;}
public OpportunityContactRoleController(ApexPages.StandardController controller){
this.oppObj = (Opportunity)controller.getRecord();
oppId = this.oppObj.Id;
oppContRoles = [SELECT Id,OpportunityId, Contact.Name, Contact.Email, Role, Contact.Account.Name, Contact.Phone, IsPrimary
FROM OpportunityContactRole WHERE OpportunityId = :((Opportunity)controller.getRecord()).Id];
}
public void deleteOppContRole(){
if(contRoleId != null){
OpportunityContactRole ocr = new OpportunityContactRole();
ocr.Id = contRoleId;
delete ocr;
oppContRoles = new List<OpportunityContactRole>();
oppContRoles = [SELECT Id,OpportunityId, Contact.Name, Contact.Email, Role, Contact.Account.Name, Contact.Phone, IsPrimary
FROM OpportunityContactRole WHERE OpportunityId = :((Opportunity)controller.getRecord()).Id];
}
}
public pageReference primaryContact() {
PageReference pageRef = Page.OpportunityPrimaryContact;
pageRef.getParameters().put('Id', oppId);
pageRef.setRedirect(true);
return pageRef;
}
}
Test Class:
@isTest
public class OpportunityContactRoleController_Test {
private static testMethod void testData(){
Account testAccount = new Account(Name = 'Test Account', Country__c = 'US');
insert testAccount;
Contact testContact = new Contact(LastName = 'Test LastName', FirstName = 'Test LastName');
insert testContact;
Opportunity testOpportunity = new Opportunity(AccountId = testAccount.Id, Name = 'Test Opportunity', Country__c = 'US',
CurrencyIsoCode = 'USD', StageName = 'Loan Current', CloseDate = date.today(), Days_In_Term__c = 2 );
insert testOpportunity;
OpportunityContactRoleController controller = new OpportunityContactRoleController(new ApexPages.StandardController(testOpportunity));
OpportunityContactRole ocr = new OpportunityContactRole();
controller.deleteOppContRole();
controller.primaryContact();
}
}
All Answers
System.NullPointerException: Attempt to de-reference a null object