trigger TeamMemberTrg on Account(after insert) {
if (trigger.isinsert) {
set parentIds = new set();
for (account acct: trigger.new) {
if (acct.ParentId != null) {
parentIds.add(acct.parentId);
}
}
if (!parentIds.isEmpty()) {
map mpAccs = new map([select id, ownerId from Account where Id in: parentIds]);
List members = new List();
for (account acct: trigger.new) {
if (acct.ParentId != null && mpAccs.containsKey(acct.ParentId)) {
members.add(New AccountTeamMember(AccountId = acct.id, TeamMemberRole = ‘Account Manager’, UserId = mpAccs.get(acct.ParentId).OwnerId));
}
}
if (!members.isEmpty())
insert members;
}
}
}
Review below links that can give more information on Account teams.
It looks like our team of experts can help you resolve this ticket. We have Salesforce global help-desk support and you can log a case and our Customer Success Agents will help you solve this issue. You can also speak to them on live chat. Click on the below link to contact our help-desk. Trust me it is a support service that we are offering for free!
This blog might answer your query,
https://developer.salesforce.com/forums/?id=9060G0000005gZnQAI
Thanks!
Try below snippet.
Review below links that can give more information on Account teams.
https://help.salesforce.com/articleView?id=000313342&language=en_US&type=1&mode=1
https://success.salesforce.com/answers?id=90630000000gzCSAAY
Hope above information was helpful.
Please mark as Best Answer so that it can help others in the future.
Thanks,
Vinay Kumar
It looks like our team of experts can help you resolve this ticket. We have Salesforce global help-desk support and you can log a case and our Customer Success Agents will help you solve this issue. You can also speak to them on live chat. Click on the below link to contact our help-desk. Trust me it is a support service that we are offering for free!
https://jbshelpdesk.secure.force.com
Thanks,
Jarvis SFDC team