You need to sign in to do that
Don't have an account?
Sinka Tinko 1
What am I doing wrong here
public static void OnAfterInsert(List < Opportunity > newOpps) {
List<OpportunityTeamMember> opptList = new List<OpportunityTeamMember>();
for(Opportunity opp : newopps) {
List<Account> acclist = [Select id, name, owner.division from account where id = :opp.account.id ];
for (account a : acclist) {
if (a.owner.division == 'Payback') {
opportunityteammember opptm = new opportunityteammember(
TeamMemberRole = 'Account Manager',
OpportunityId = opp.id,
UserId = opp.Ownerid);
opptList.add(opptm);
}
insert opptList;
}
}
}
List<OpportunityTeamMember> opptList = new List<OpportunityTeamMember>();
for(Opportunity opp : newopps) {
List<Account> acclist = [Select id, name, owner.division from account where id = :opp.account.id ];
for (account a : acclist) {
if (a.owner.division == 'Payback') {
opportunityteammember opptm = new opportunityteammember(
TeamMemberRole = 'Account Manager',
OpportunityId = opp.id,
UserId = opp.Ownerid);
opptList.add(opptm);
}
insert opptList;
}
}
}
When you are querying acclist using Opportunity's AccountID, you can use opp.accountid.
Please find below modified code.
Let us know if that helps you.
Best Regards,
BALAJI
All Answers
You wrote dml inside for loop which is wrong way of coding, Make sure you write dml after for loop.
When you are querying acclist using Opportunity's AccountID, you can use opp.accountid.
Please find below modified code.
Let us know if that helps you.
Best Regards,
BALAJI
Thanks so much for your help. It worked.