-3
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

  • 5
    And your question is? – Girbot Jan 29 '18 at 14:22
  • I am getting this error DML requires SObject or SObject list type: AccountTeamMember – Anish Kumar Jan 29 '18 at 17:42
3

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 respective AccountShare at the same time while creating the AccountTeamMember. 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:

  1. Has SOQL in a for loop (Why? governor limits)
  2. Has DML in a for loop (Why? governor limits)
  3. Has logic in the trigger itself (Why? lots of reasons!)
  4. It's not bulkified

Below is an example of a better approach. It is deliberately not complete.

Trigger

trigger exAccountTrigger on Account (before insert, after insert,before update, after update) {

    if(trigger.isBefore){
        //Before Trigger methods here
    }

    if(trigger.isAfter){
        if(trigger.isInsert){
            exAccountHelper.createTeamMember(Trigger.new);
        }
    }

}

Helper Class

public without Sharing class exAccountHelper {
    public static void createTeamMember(List<Account> newAccs){
        List<AccountTeamMember> accMemLsit = new List<AccountTeamMember>();
        //Create AccountTeamMember logic here
        //Left as an exercise for the reader

        insert accMemLsit;
    }
}
  • Sir the error is on line 7,8,9,10 Variable does not exist: AccountId, Variable does not exist: UserId, Variable does not exist: TeamMemberRole , DML requires SObject or SObject list type: AccountTeamMember – Anish Kumar Jan 29 '18 at 18:57
  • I didn't understand why this issue is coming DML requires SObject or SObject list type: AccountTeamMember – Anish Kumar Jan 30 '18 at 5:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.