douglascayers / sfdc-preserve-chatter-files-on-lead-conversion

Simple Lead trigger that moves Chatter Files to the converted Account, Contact, and Opportunity upon Lead Conversion.
https://douglascayers.com/2016/11/10/preserve-chatter-files-on-lead-conversion/
BSD 3-Clause "New" or "Revised" License
3 stars 0 forks source link

Test Coverage Issue #1

Open Nahumancer opened 7 years ago

Nahumancer commented 7 years ago

Hi Douglas!,

For some reason, the test class only covers 50% of the Handler code. It covers until line 71: for ( ContentDocumentLink fileLink : fileLinks ) { meaning that it did not create those fileLinks correctly.

This org is using PersonAccounts, I am wondering whether that might be the root cause. I will try debugging and if I find the problem I will post it here.

douglascayers commented 7 years ago

I get 100% code coverage for the apex class and trigger in my dev org, but I do not have PersonAccounts capability.

In your org with PersonAccounts, do any of the files get moved automatically to the converted Account, Contact, or Opportunity already? The only way that line 71 would not run during the unit test is if the Chatter Files have already been moved to another record (or deleted).

Are there other triggers or packages installed in the org that may be interfering?

If I recall correctly, even if PersonAccounts is enabled, lead conversion still creates a business Account and Contact unless the lead's company is blank. In my unit test I explicitly set Company to "Salesforce".

I'm assuming you've installed this in a sandbox. Do you see desired behavior in the sandbox with both Leads => Business Account + Contact and with Leads => Person Account? That is to say, is the issue just with the unit test or does the code not have expected results in your org at all?

Thanks

Nahumancer commented 7 years ago

Douglas,

The desired behaviour is achieved correctly, manual/functional tests run perfectly OK. It is just the automated tests that fail. I tried both setting a Company and not setting a Company on the Lead. There are no other triggers installed, it's a fresh org, with PersonAccounts enabled.

Unfortunately, I have to keep working on other stuff right now and can't troubleshoot this further. But thanks a lot for your assistance and for sharing this with the community! :)

Cheers!, Nahuel.