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 Opportunity.id in :OpportunityIds
                                          and TeamMemberRole =: 'Opportunity Owner'];

        for(Opportunity oppt :[select id,ownerId from Opportunity where Opportunity.id 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.: [] – Thirumagal.s Oct 11 '18 at 15:02
  • @Jury then, you'd have to delete the split first. You need to follow the errors' directions. – sfdcfox Oct 11 '18 at 16:10
  • Yes, But we cant write any apex code delete split assigned to opportunity know? – Thirumagal.s Oct 12 '18 at 4:19

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.