I receive the following error message when trying to upload my code to production

System.DmlException: Insert failed. First exception on row 0; first error: INVALID_CROSS_REFERENCE_KEY, Service Record Type: this ID value isn't valid for the user: 0128E0000004m8bQAA: [RecordTypeId] Stack Trace: Class.TEST_OpOwnerConvertedServiceNotif.TEST_OpOwnerConvertedServiceNotif: line 16, column 1

Below is my test class, what do I need to change, for this to upload to production?

@istest private class TEST_OpOwnerConvertedServiceNotif 
static testMethod void TEST_OpOwnerConvertedServiceNotif ()
    Account acc = new Account(Name = 'Test Account');
    insert acc;

    ID pricebookId = Test.getStandardPricebookId();

   RecordType RecType = [Select Name, Id From RecordType
              where sObjectType='Product2' and DeveloperName = 'Unavailable_R_D_Service'];

    User U = [Select Id FROM User WHERE Email = 'glenn.daly@jisc.ac.uk'];

    Product2 prd1 = new Product2 (Name = 'Test Product Entry 1', Description = 'Test Product Entry 1',
                                  productCode = 'ABC', isActive = false,
                                  RecordTypeId = RecType.id,
                                  R_D_Service_Owner__c = u.Id,
                                  Convert_to_Service_Catalogue_Initiated__c = TRUE,
                                  Convert_to_Service_Catalogue_Emailed__c = FALSE);
                                    insert prd1;
    PricebookEntry pbe1 = new PricebookEntry
        (Product2ID=prd1.id, Pricebook2ID = pricebookId,UnitPrice=0, isActive=true);
            insert pbe1;

    Opportunity opp1 = new Opportunity (Name='Opp1', StageName='Proposal Accepted', CloseDate=Date.today(),
                                        Pricebook2Id = pbe1.Pricebook2Id, AccountId = acc.id);
                                        insert opp1;

    OpportunityLineItem lineItem1 = new OpportunityLineItem
        (OpportunityID = opp1.id, PriceBookEntryID = pbe1.id, quantity=1, totalprice=0);
    insert lineItem1;

      OpOwnerConvertedServiceNotif sobj = new OpOwnerConvertedServiceNotif();
 system.schedule('Scheduable_Class', '0 0 23 * * ?', sobj);


  • 5
    You have a hard coded Id. SF Ids will not sync from org to org. Query for R_D_Service_Owner__c like you did for the RecordType.Id. – Jesse Milburn Feb 13 '17 at 14:13
  • 1
    I see only one problem for now -- that is hardcoded id for R_D_Service_Owner__c -- 005w0000004x3RiAAI. It would be better to generate user in test method, and use it's id to ensure that it is always available – kurunve Feb 13 '17 at 14:13
  • @JesseMilburn i've updated my code, and still have the same problem when trying to upload to production – Glenn Daly Feb 13 '17 at 14:48

This error is telling you that the specified user profile doesn't have access to the record type you're trying to use (the 'Unavailable_R_D_Service' record type on 'Product2'). You can just go in to Setup, add the record type to the System Administrator profile, and then re-run your change set deployment.

  • I have gone into production, ensured sys admin has access to 'Unavailable_R_D_Service' record type on 'Product2' yet I stil have the same issue? I've also updated my code to take into account what Jesse said – Glenn Daly Feb 13 '17 at 14:49

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.