Getting an error like An Apex error occurred: System.SObjectException: Field is not writeable: OpportunityTeamMember.UserId

public class BD_UPDATEOppTeam {

    public static void OppTeamDelete(List<Id> OpportunityIds)
        List<OpportunityTeamMember> mem = [select id,UserId from OpportunityTeamMember
                                          where in :OpportunityIds
                                          and TeamMemberRole =: 'Opportunity Owner'];

        for(Opportunity oppt :[select id,ownerId from Opportunity where in :OpportunityIds]){

            for(OpportunityTeamMember team :mem){
                 team.UserId= oppt.ownerId;

        update mem;


How to resolve this issues? Please help me.

The field cannot be written to, because it is listed as "creatable" only. You must delete the old record and create a new record.

  • Hi, but when I tried to delete it cause the this error : FATAL_ERROR System.DmlException: Delete failed. First exception on row 0 with id 00qK0000003mcOUIAY; first error: INVALID_CROSS_REFERENCE_KEY, Can't remove a team member assigned to a split from an opportunity.: [] – Jury Oct 11 at 15:02
  • @Jury then, you'd have to delete the split first. You need to follow the errors' directions. – sfdcfox Oct 11 at 16:10
  • Yes, But we cant write any apex code delete split assigned to opportunity know? – Jury Oct 12 at 4:19

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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