trigger AccountTeam on Account (after insert) {
if(Trigger.isInsert){
for(account acct : Trigger.new){
if(acct.ParentId!=null && acct.VPA__c==false){
Account Parentacct=[SELECT Id, OwnerId FROM Account WHERE Id=:acct.ParentId LIMIT 1];
System.debug(Parentacct +'parentaccount');
AccountTeamMember acctmem = new AccountTeamMember();
acctmem.AccountId = acct.Id;
System.debug(acct.Id + 'id');
acctmem.UserId = Parentacct.OwnerId;
acctmem.TeamMemberRole = 'Account Manager';
System.debug(acctmem +'accounteam');
insert acctmem;
}
}
}
}
—
The following error is thrown:
DML requires SObject or SObject list type: AccountTeamMember
Best Answer
I am adding this as answer as I wanted to help you more than a comment would allow. Your question has been downvoted as it shows a lack of effort on your part and is not clear what you are asking. Please read how to ask a question. More information would be helpful here, is that the full error message? No line number or class mentioned?
Now trying to help you...
I tried your trigger as is (minus the field VPA__c) in a dev org and it worked fine. The difference may be due to
Account
access settings, mine is public read/write. This example adds the respectiveAccountShare
at the same time while creating theAccountTeamMember
. I do not know this for a fact, just a suggestion.The bad news / constructive feedback
You need to read up on Apex Best Practices. Your trigger:
Below is an example of a better approach. It is deliberately not complete.
Trigger
Helper Class