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
V100V100 

Looking for some help on test class in managed app on Standard object

I am developing an app that has classes interacting with some stanrd objects; User ofr instance.

Typically when writing the test classes for this type i would create a user within the test to test against, as per SF design principals.

 

I am not sure how to tackle this from an managed app point of view as i could try to create a user, however the host org has a custom field that is required for that record.

Will that fail my test class and does that matter from the host org's point of view.

Will it be ignore in the managed app, or not matter somehow.

 

Thanks for any help.

 

Best Answer chosen by Admin (Salesforce Developers) 
DarrellDDarrellD

I think I understand and, if I do, the answer about creating the user is that the test should pass when you run it in your Development org and...yes, it would then likely fail in the user org if there is a required field that you do not cover in your test.

 

You can get complicated in your test if you expect this to come up frequently and use Describe statements, but that may be overkill.  You can choose on Oninstall=(True/False) to overcome this.  I believe this option exists for the type of scenario you outline.  So the test class won't run when the user installs the app.  There are obvious downsides here.

 

If it's a one-off, could ask to make field non required while installing app and then require again.  Finally, if it's only required on Page Layout, then you are fine and test will be fine. I was assuming you mean required on the Contact object.

 

Basically if user org has requirements that affect your app, you have to cover this possibilities in your testing or, if it runs, it may fail.

All Answers

DarrellDDarrellD

I think I understand and, if I do, the answer about creating the user is that the test should pass when you run it in your Development org and...yes, it would then likely fail in the user org if there is a required field that you do not cover in your test.

 

You can get complicated in your test if you expect this to come up frequently and use Describe statements, but that may be overkill.  You can choose on Oninstall=(True/False) to overcome this.  I believe this option exists for the type of scenario you outline.  So the test class won't run when the user installs the app.  There are obvious downsides here.

 

If it's a one-off, could ask to make field non required while installing app and then require again.  Finally, if it's only required on Page Layout, then you are fine and test will be fine. I was assuming you mean required on the Contact object.

 

Basically if user org has requirements that affect your app, you have to cover this possibilities in your testing or, if it runs, it may fail.

This was selected as the best answer
V100V100

Darrell

Thanks for the comprehensive answer, think the onInstall is the answer I was looking for.

Great job