Good evening, I have been at the office since 0700 this morning and it is now 2309. I have the majority of all of the trigger and everything situated for my new custom object except for this last piece. I need to automatically assign the AccountTeamMember and TeamMemberRole to the New Account when an Account Request is converted to an actual Account.

The following is what I have... thank you in advance!

trigger addAccountTeamMember on Account_Request__c (after insert){    

    List<Account> AccountTeamMember = new List<Account>();

    for (Account_Request__c ar : Trigger.new){
        if(ar.Account_Request_Status__c == 'Convert'){
            AccountTeamMember.TeamMemberRole = ar.Account_Team_Role__c,
            AccountTeamMember.UserId = ar.Account_Team_Owner__c;

    insert AccountTeamMember;

I'm not familiar with AccountTeamMember and TeamMemberRole and so cannot comment on the logical sense of what you are doing.

But based on your code, here is how I would code the AccountTeamMember case and you can add similar code for the TeamMemberRole case:

trigger addAccountTeamMember on Account_Request__c (after insert) {    
    // Will collect the object to be inserted in this list
    List<AccountTeamMember> atms = new List<AccountTeamMember>();
    // Loop over the one or more inserted objects
    for (Account_Request__c ar : Trigger.new) {
        if (ar.Account_Request_Status__c == 'Convert') {
            // Create a new object, initialising some values at the same time
            AccountTeamMember atm = new AccountTeamMember(
                    AccountId = ???,
                    UserId = ar.Account_Team_Owner__c,
                    TeamMemberRole = ar.Account_Team_Role__c
            // Add the new object to the list
    // Insert all the objects in the list (bulkification)
    insert atms;

PS Found this Sharing and Team Selling Objects ERD that is helpful.

  • Good morning Keith C, I got the information from SalesForce referring to what I am trying to work do. salesforce.com/developer/docs/api/Content/… Is the website where I tried to gain my information from... does this make clear it up now? Nov 21 '14 at 17:44
  • @DonaldBohrisch That helps (TeamMemberRole is a field not an object) and I added an ERD link to the answer. What is missing is the Account ID: is that also available in the Account_Request__c object? If so just replace the ??? with ar.WhataverTheFieldNameIs__c.
    – Keith C
    Nov 21 '14 at 18:18
  • my apologies for the late reply... been swamped out here and ended up needing to jump on another project. Hope you had a great thanksgiving. I do not have the Account ID on this page. Basically what happens is when the information that is on this page is saved as "convert" it creates a new Account Record as well as a new Contact Record and associates the Contact with the Account automatically. The only thing left now is to automatically associate the Creator of this request as an AccountTeamMember on the Account Record. Dec 15 '14 at 18:54

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.