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

Test Class Failing with 0% Test Coverage
My Trigger is as follows:-
trigger opportunityAcountTeam on Opportunity (after insert, after update) {
LIST<Opportunity> listOpp = new LIST<Opportunity>();
SET<ID> oppIds = new SET<ID>();
LIST<AccountTeamMember> listAccTeamMember = new LIST<AccountTeamMember>();
//LIST<AccountShare> listShare = new LIST<AccountShare>();
if(Trigger.IsAfter && Trigger.IsInsert) {
for(Opportunity newOpp : Trigger.new) {
if(newOpp.Probability == 20) {
if(String.isEmpty(newOpp.AccountId)) {
newOpp.addError('Account name cannot be blank');
return;
}
listOpp.add(newOpp);
oppIds.add(newOpp.AccountId);
AccountTeamMember newAccMember = new AccountTeamMember();
newAccMember.AccountAccessLevel = 'Edit';
newAccMember.OpportunityAccessLevel = 'Read';
newAccMember.TeamMemberRole = 'Account Manager';
newAccMember.AccountId = newOpp.AccountId;
newAccMember.UserId = newOpp.OwnerId;
newAccMember.Account = newOpp.Account;
//AccountShare newAccShare = new AccountShare();
//newAccShare.AccountAccessLevel='Read';
//newAccShare.OpportunityAccessLevel = 'Read Only';
//newAccShare.CaseAccessLevel='Read Only';
//newAccShare.AccountId = newOpp.AccountId;
//newAccShare.UserOrGroupId = newOpp.OwnerId;
listAccTeamMember.add(newAccMember);
system.debug('team' + listAccTeamMember);
//listShare.add(newAccShare);
if(listAccTeamMember != NULL) {
insert listAccTeammember;
}
}
}
}
}
My test class is as follows:-
@isTest
public class oppAccTeamMember {
static testMethod Void testOppAccTeamMember() {
LIST<Opportunity> newOpp = new LIST<Opportunity>();
LIST<AccountTeamMember> newTeamMember = new LIST<AccountTeamMember>();
LIST<Account> listAcc = new LIST<ACCOUNT>();
SET<ID> allIds = new SET<ID>();
Profile pld= [SELECT Id FROM Profile WHERE Name = 'Standard User' LIMIT 1];
User u= new User();
u.LastName = 'ttt';
u.ProfileId = Pld.Id;
insert u;
Account newAcc = new Account();
newAcc.Name = 'Starting';
newAcc.OwnerId = u.Id;
listAcc.add(newAcc);
insert listAcc;
Opportunity createOpp = new Opportunity();
createOpp.Name = 'First';
createOpp.CloseDate = Date.today();
createOpp.StageName = 'Prospecting';
createOpp.AccountId = newAcc.Id;
allIds.add(createOpp.AccountId);
if(String.isEmpty(createOpp.AccountId)) {
createOpp.addError('Account name cannot be blank');
return;
}
newOpp.add(createOpp);
insert newOpp;
AccountTeamMember createTeam = new AccountTeamMember();
createTeam.accountId = createOpp.AccountId;
createTeam.AccountAccessLevel = 'Read';
createTeam.UserId = createOpp.OwnerId;
newTeamMember.add(createTeam);
insert newTeamMember;
}
}
My test class is failing and it is giving me System.DMLException Insert failed
Please provide assistance as I am stuck with for many days and I do not just want to forget about it because by doing that I am not going to learn for the next time.
Thanks
Vijay
trigger opportunityAcountTeam on Opportunity (after insert, after update) {
LIST<Opportunity> listOpp = new LIST<Opportunity>();
SET<ID> oppIds = new SET<ID>();
LIST<AccountTeamMember> listAccTeamMember = new LIST<AccountTeamMember>();
//LIST<AccountShare> listShare = new LIST<AccountShare>();
if(Trigger.IsAfter && Trigger.IsInsert) {
for(Opportunity newOpp : Trigger.new) {
if(newOpp.Probability == 20) {
if(String.isEmpty(newOpp.AccountId)) {
newOpp.addError('Account name cannot be blank');
return;
}
listOpp.add(newOpp);
oppIds.add(newOpp.AccountId);
AccountTeamMember newAccMember = new AccountTeamMember();
newAccMember.AccountAccessLevel = 'Edit';
newAccMember.OpportunityAccessLevel = 'Read';
newAccMember.TeamMemberRole = 'Account Manager';
newAccMember.AccountId = newOpp.AccountId;
newAccMember.UserId = newOpp.OwnerId;
newAccMember.Account = newOpp.Account;
//AccountShare newAccShare = new AccountShare();
//newAccShare.AccountAccessLevel='Read';
//newAccShare.OpportunityAccessLevel = 'Read Only';
//newAccShare.CaseAccessLevel='Read Only';
//newAccShare.AccountId = newOpp.AccountId;
//newAccShare.UserOrGroupId = newOpp.OwnerId;
listAccTeamMember.add(newAccMember);
system.debug('team' + listAccTeamMember);
//listShare.add(newAccShare);
if(listAccTeamMember != NULL) {
insert listAccTeammember;
}
}
}
}
}
My test class is as follows:-
@isTest
public class oppAccTeamMember {
static testMethod Void testOppAccTeamMember() {
LIST<Opportunity> newOpp = new LIST<Opportunity>();
LIST<AccountTeamMember> newTeamMember = new LIST<AccountTeamMember>();
LIST<Account> listAcc = new LIST<ACCOUNT>();
SET<ID> allIds = new SET<ID>();
Profile pld= [SELECT Id FROM Profile WHERE Name = 'Standard User' LIMIT 1];
User u= new User();
u.LastName = 'ttt';
u.ProfileId = Pld.Id;
insert u;
Account newAcc = new Account();
newAcc.Name = 'Starting';
newAcc.OwnerId = u.Id;
listAcc.add(newAcc);
insert listAcc;
Opportunity createOpp = new Opportunity();
createOpp.Name = 'First';
createOpp.CloseDate = Date.today();
createOpp.StageName = 'Prospecting';
createOpp.AccountId = newAcc.Id;
allIds.add(createOpp.AccountId);
if(String.isEmpty(createOpp.AccountId)) {
createOpp.addError('Account name cannot be blank');
return;
}
newOpp.add(createOpp);
insert newOpp;
AccountTeamMember createTeam = new AccountTeamMember();
createTeam.accountId = createOpp.AccountId;
createTeam.AccountAccessLevel = 'Read';
createTeam.UserId = createOpp.OwnerId;
newTeamMember.add(createTeam);
insert newTeamMember;
}
}
My test class is failing and it is giving me System.DMLException Insert failed
Please provide assistance as I am stuck with for many days and I do not just want to forget about it because by doing that I am not going to learn for the next time.
Thanks
Vijay
try following apex test class with 90% code coverage.
I hope this time it will help you.
let me know if it helps you and marking it as best answer.
Thank you
All Answers
You are inserting many items in the test class and based on the error message, I am unsure which insert is failing. Can you please provide the stack trace/ line number?
Thanks for your reply. Just to let you know all Insert statements are giving that error in the test class.
Thanks
Vijay
Following are inserts that are giving System.DMLException Insert failed
insert u;
insert listAcc;
insert newOpp;
insert newTeamMember;
Thanks
Vijay
try following apex test class with 90% code coverage.
I hope this time it will help you.
let me know if it helps you and marking it as best answer.
Thank you
Thanks for your help. Yes it is working with modifications that you suggested.
Thanks again
Vijay