I am trying to create Opportunity Team Member
using External id's for Opportunity
and User
.
First of all I create an instance of Opportunity and User using their respective External Id's
User teamUser = new User(User_External_ID__c =reader.getText());
Opportunity req = new Opportunity(Opportunity_External_ID__c = reqNumber);
I then create an instance of Opportunity Team Member
OpportunityTeamMember teamMember = new OpportunityTeamMember(Opportunity = req, User = teamUser, TeamMemberRole = 'FM');
Once I do an upsert
of for teamMember
, it gives me an error saying
VF_PAGE_MESSAGE OpportunityTeamMember: bad field names on insert/update call: User, Opportunity
System.DmlException: Upsert failed. First exception on row 0; first error: INVALID_FIELD_FOR_INSERT_UPDATE, OpportunityTeamMember: bad field names on insert/update call: User, Opportunity: [User, Opportunity]
VARIABLE_ASSIGNMENT [1675]|e|"common.apex.runtime.impl.DmlExecutionException: Upsert failed. First exception on row 0; first error: INVALID_FIELD_FOR_INSERT_UPDATE, OpportunityTeamMember: bad field names on insert/update call: User, Opportunity: [User, Opportunity]"|0x19dcd463
When I use UserId
and OpportunityId
instead of User
and Opportunity
OpportunityTeamMember teamMember = new OpportunityTeamMember(OpportunityId = req, UserId = teamUser, TeamMemberRole = 'FM');
It errors out saying expecting Salesforce id for Opportunity and User (which makes sense).
I am now not sure what I am missing when inserting Opportunity Team Members using external Id's for Opportunity and User.
OpportunityId
withreq.Id
and theUserId
withteamUser.Id
?