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
shrey.tyagi88@tcs.comshrey.tyagi88@tcs.com 

Process Flow in Change Set fails to create test records during validation.

HI All,
    I have a scenario which I want to discuss and confirm whether the anyone else has experienced the same issue or not. 

I am deploying a change set of 400 components. The flows are in that change set alnong with the test classes. Now, I use flows to create records of custom object "Project Review" and then I have written test classes that fetch those newly created "Project Review" records . When I run my tests in sandbox (with active flow) all of the test cases pass and I get good coverage. But when I validate the same change set for deployment , exactly at point where "Project Review "records are queried in test class - A list has no records error gets thrown out to me. 

Salesforce Says : 'An active flow in a change set is deployed to its destination as inactive. Activate the flow manually after deployment.' 

I googled this and found that even active flows upon deployment are deactivated initially. Is this the reason why I may be facing this issue ? Becuase my active flows of change sets are deactivated initially upon deployment , I dont get any records created for my test class and exception error gets in .



Just want to confirm my guess here. Thanks for your help ...


Regards
Shrey Tyagi
Zuinglio Lopes Ribeiro JúniorZuinglio Lopes Ribeiro Júnior
Hello Shrey,

I think you're facing two different problems. One is related to the deployment of the flow and the other is in which data your test class is relying on.
Test Classes are not supposed to see real data from the organization unless your set your test class to do it so. 

Are your test class set with the @isTest(SeeAllData=true) annotation? If so, you're relying on real data from your org which means unless you created the data in the destination sandbox/production before the deployment of your test class it's going to fail because it won't find data.

As a best practice you should avoid this annotation and create all data you need within your test class.

Please take a look in the following links:
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_testing_data_access.htm
https://developer.salesforce.com/page/An_Introduction_to_Apex_Code_Test_Methods
https://trailhead.salesforce.com/en/modules/apex_testing

Hope to have helped!

Regards.

Don't forget to mark your thread as 'SOLVED' with the answer that best helps you.
 
shrey.tyagi88@tcs.comshrey.tyagi88@tcs.com
Zuilglio- Thanks a lot for your time and effort on this. I think my issue is related more t the deployment of the flow. The data that I am using in my test class is not the actual data . The scenario is like this, in a parent record a check box changes from false to true I create a child record. This is what I am doing in my test class. Creating a dummy parent record and toggling the checkbox and querying the child record with dummy parent record id(none of the records are real). Now when I query the child it fails. 

Reason: The process flow (which is responsible for child record creation) does not fire as it is inactive.

So my question is this, what changes can I do in my test class to imitate the process builder fire so that my apex invocable method gets covered.