You need to sign in to do that
Don't have an account?
Vijay Zutshi 2
opportunityAcountTeam caused an unexpected exception
Hi,
When I create the Opportunity with the Probability=20, then the opportunity owner will be automatically added to Account Team of the associated account for that Opportunity. My tigger 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) {
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;
//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);
//listShare.add(newAccShare);
if(listAccTeamMember != NULL) {
insert listAccTeammember;
}
}
}
}
}
I am getting following error:-
opportunityAcountTeam: execution of AfterInsert caused by: System.DmlException: Insert failed. First exception on row 0; first error: REQUIRED_FIELD_MISSING, Required fields are missing: [Account]: [Account]: Trigger.opportunityAcountTeam: line 27, column 1
Kindly advise as I am not able to solve the problem.
Thanks
Vijay Zutshi
When I create the Opportunity with the Probability=20, then the opportunity owner will be automatically added to Account Team of the associated account for that Opportunity. My tigger 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) {
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;
//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);
//listShare.add(newAccShare);
if(listAccTeamMember != NULL) {
insert listAccTeammember;
}
}
}
}
}
I am getting following error:-
opportunityAcountTeam: execution of AfterInsert caused by: System.DmlException: Insert failed. First exception on row 0; first error: REQUIRED_FIELD_MISSING, Required fields are missing: [Account]: [Account]: Trigger.opportunityAcountTeam: line 27, column 1
Kindly advise as I am not able to solve the problem.
Thanks
Vijay Zutshi
please try below code.
Apex class:
Trigger: