You need to sign in to do that
Don't have an account?

Enabling OpportunitySplits broke Test Codes in Sandbox
I recently turned on Overlay Opportunity Splits in one of my sandboxes. Now Test Code that previously worked is erroring with the following:
INVALID_CROSS_REFERENCE_KEY, Unable to create an opportunity team member for new opportunity split user.: [SplitOwnerId]
As you can see the code below isn't trying to insert a Team Member or OpportunitySplit so I've been going crazy trying to fix the issue. When I create an opportunity manually, an OpportunitySplit is NOT automatically created. I am stumped.
INVALID_CROSS_REFERENCE_KEY, Unable to create an opportunity team member for new opportunity split user.: [SplitOwnerId]
As you can see the code below isn't trying to insert a Team Member or OpportunitySplit so I've been going crazy trying to fix the issue. When I create an opportunity manually, an OpportunitySplit is NOT automatically created. I am stumped.
@isTEst Private class TestUpdateStormStatusonOppty{ static testMethod void UpdateStormStatus() { //create a user to run the test as Profile p = [Select id from Profile where name = 'CDS']; User u = new User(alias = 'mo123', email='mousey.1234@covance.com', emailencodingkey='UTF-8', lastname='123', languagelocalekey='en_US', localesidkey='en_US', profileid = p.Id, country='United States', CVD_Division__c='CDS', User_Type__c='AE', timezonesidkey='America/Los_Angeles', username='mousey.1234@covance.com'); insert u; //create an oppty with required fields RecordType RecType = [Select Id From RecordType Where SobjectType = 'Opportunity' and DeveloperName = 'CDS']; Opportunity o = new Opportunity(Name='TestMethodMouse1', AccountId='001C000000nGrv3', Compound__c='a08C000000Gva2H', RecordTypeId=RecType.Id, CloseDate=System.Today(), StageName='Prospect', NextStep='test', Study_Phase__c='PreClinical', Probability_of_Win__c='10%', Integrated_Opportunity2__c='No', Primary_Contact_Role_Assigned__c=true); insert o; RFI_Status__c CSWA = new RFI_Status__c( Opportunity__c=o.id, Storm_Status__c='Current Opportunity', Triage_Outcome__c='No Go'); Test.startTest(); insert CSWA; Test.stopTest(); Opportunity op=[SELECT Related_Storm_Status__c, Id FROM Opportunity WHERE Id=:o.id]; System.assertEquals(op.Related_Storm_Status__c,'Current Opportunity'); } }
OwnerId=u.id
All Answers
We have a similar post earlier:
https://developer.salesforce.com/forums/?id=906F0000000ApANIA0
Please try to run it using the runAs() method and see if it works.
Also check the split settings for the below check box:
Let users add members to opportunity teams while editing splits. --- Checked / Unchecked
Regards,
Mahesh
OwnerId=u.id