douglascayers / sfdc-convert-notes-to-chatter-notes

📓 Easily migrate your Notes to Enhanced Notes.
https://douglascayers.com/2017/05/08/convert-notes-to-enhanced-notes/
BSD 3-Clause "New" or "Revised" License
26 stars 11 forks source link

ConvertNotesToContentNotesServiceTest fails if no Partner Community is enabled in the org #6

Closed sfdcmatt closed 7 years ago

sfdcmatt commented 7 years ago

The ConvertNotesToContentNotesServiceTest.test_partner_community_users() method fails at line 25 when Communities isn't enabled in an org, because it can't find a Profile with the specified name. Error message is:

List has no rows for assignment to SObject stack Class.ConvertNotesToContentNotesServiceTest.test_partner_community_users: line 25, column 1

Instead of binding to a single sObject instance, it should bind to a collection and inspect if the collection is null, then branch / handle accordingly.

douglascayers commented 7 years ago

Good point @sfdcmatt

I'm thinking of adding an initial check at start of the test method to see if communities are even enabled. If not then exit gracefully otherwise continue on. The check would be like I did in the attachment conversion project:

Boolean communitiesEnabled = ContentVersion.sObjectType.getDescribe().fields.getMap().containsKey( 'NetworkId' );

If communities are enabeld then the org should have the standard profile for the test method to use. If not then the test still has to fail if the profile can't be found.

Besides all that, yes, I agree with your recommendation that it's best practice to query for list, check size, react accordingly.

Thanks!

sfdcmatt commented 7 years ago

Thanks!