function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
James WróbelJames Wróbel 

Production code deployment not working due to failed test

Hi, we have some Apex classes to deploy to our production org however one of the test classes is failing preventing us from being able to continue. It looks like it is not able to create a test User record in production. There were no issues with this test in lower environments, only when attempting to deploy to production. The profiles are the same across environments so I dont expect that to be the issue. Are there any additional settings that need to be made to create this kind of test data in a production org?

Thanks!
James
Sai PraveenSai Praveen (Salesforce Developers) 
Hi James,

Can you let us know what exactly the error while running the test class?

Thanks.
James WróbelJames Wróbel
It errors at the point of attempting to reference a test record that was previously created in the test run, however, it does not appear to have been created, hence the string 'No Individual'.

Test failure, method: IndividualUtilitiesCustomTest.getIndividualIdFromUserPositive -- System.StringException: Invalid id: No Individual stack Class.IndividualUtilitiesCustomTest.getIndividualIdFromUserPositive: line 178, column 1Test failure, method: IndividualUtilitiesCustomTest.getIndividualIdFromUserPositive -- System.StringException: Invalid id: No Individual stack Class.IndividualUtilitiesCustomTest.getIndividualIdFromUserPositive: line 178, column 1
Sai PraveenSai Praveen (Salesforce Developers) 
Hi James,

Is your test class contains (seealldata=true)?

This error is not generic so have to go through code .

Thanks,
 
James WróbelJames Wróbel
Hi,

No, seealldata=true has not been set in the test class.

Basically, the test class runs and creates some records of different objects, i.e. Account, Contact, User. When it comes to accessing the User record that it should have created, it does not seem to be able to find/access that record. I am wondering if there are any restrictions or some setting that is required to allow test data of this kind to be created in a production environment? This test works without issue in all our other non-production environments, it only fails when attempting to run against production hence the suggestion that it might be an org specific issue.

Thanks.
Sai PraveenSai Praveen (Salesforce Developers) 
Hi,

Can you confirm with which user you are running create user ? May be your user does not have permisison to create user in production org. Did you check ?

Thanks
 
James WróbelJames Wróbel
Hi,

It is using our Copado integration user account that has system admin access. There doesn't appear to be many settings in the profile around the User object but all looks ok (the same settings as in other environments). There are also a number of system permissions within the Admin profile around user management, but these are all set to true. The profile reflects the access in our other non-prod environment that are working so I assuming it isn't the root cause.

Thanks.