• Ravi Shankar Reddy
  • NEWBIE
  • 0 Points
  • Member since 2017

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 1
    Replies

Hi All

 

I got stuck with this so I thought of asking it here. Any help would be highly appreciated.

 

Well, I am trying to write a test class wherein an AccountTeamMember record is created. I am not able to assign a value to the UserId. The following is the error:

 

Field is not writeable: AccountTeamMember.UserId

 

The following is the code:

 

@isTest
private class TestFox {
static testMethod void testTriggerContactMAMDforCO() {
Map<String, Id> recordTypes = new Map<String, Id>();
for (RecordType rt : [SELECT Id, SObjectType, DeveloperName FROM RecordType]) {
recordTypes.put('' + rt.SObjectType + rt.DeveloperName, rt.Id);
}


// Create an Entity
Account acct = new Account(name='Test Corporation',Sales_Report_Code__c='5000',RecordTypeId = recordTypes.get('AcctBr'));
insert acct;

// Create an Entity Team
AccountTeamMember atmMD = new AccountTeamMember(AccountId=acct.Id,TeamMemberRole='Marketing Dir', UserId='005E0000000KojD');
insert atmMD;

AccountTeamMember atmMA = new AccountTeamMember(AccountId=acct.Id,TeamMemberRole='Marketing Ass', UserId='005E0000000JaQD');
insert atmMA;


// Create a Contact and assign it an account
Contact con = new Contact(AccountId=acct.Id,lastname='lasty',firstname='firsty',BAD__c=true,RecordTypeId = recordTypes.get('CAD'));

//Now insert data ......
Test.startTest();
insert con;

// Now change the Account's Sales_Report_Code__c and Account Channel
acct.Sales_Report_Code__c='1234';
acct.Channel__c='Company Offices';
update acct;

// Update the Account Team Member users
atmMD.UserId='005E0000000JF9m';
update atmMD;

atmMA.UserId='005E0000000K9aE';
update atmMA;

// Update the contact , any field other than Marketing Dir & Marketing Ass
con.FirstName='firstyyyy';
con.BAD__c=false;
update con;
System.assertEquals(con.Marketing_Dir__c,'005E0000000JF9m');
System.assertEquals(con.Marketing_Ass__c,'005E0000000K9aE');

Test.stopTest();
}
}

 

Any suggestion what can be done better here to eliminate the error? 

 

Thank you

g