(I'll refer to A as the sending instance and B as the receiving instance)

We have a trigger on instance B re-populating a regular lookup field. It is triggered when there's a change to a hidden field containing the parent ID of a record from the instance A. When there's a change to this field (let's say from null to a valid ID), the trigger is requesting the PartnerNetworkRecordConnection record where the ParentRecordId field is equal to the new ID and where the ConnectionId is equal to an ID set in a Custom Setting. Then, the trigger updates the local Parent Record lookup in B using the LocalRecordId field.

Now, I'm wondering how I can unit test this module. Insert DML requests on PartnerNetworkConnection are not allowed, while all the DML requests I make on PartnerNetworkRecordConnection are giving me this error:

System.DmlException: Insert failed. First exception on row 0; first error: INVALID_PARTNER_NETWORK_STATUS, invalid status for partner network operation: []

Any idea?

  • 1
    It's been a while since I've dealt with S2S, but I was able to unit test insertion of PNRC records about a year ago. My unit test code had SeeAllData=true set, and I first queried for a pre-existing PartnerNetworkConnection and used that as the ConnectionId for the inserted record. That may help you out, although it obviously makes your unit tests data-dependent. – jkraybill Aug 2 '13 at 3:56
  • @jkraybill Yes, I thought of that idea, but still didn't put it in place for the same reason (unit test being data dependant). I'll keep on searching for a solution. If I find no solution, ah well, it will not be the only time I need to apply minor tweaks to pass coverage. – jpmonette Aug 2 '13 at 14:16

Similar to the comment @jkraybill had above, I found the only way to actually test was to set seeAllData to true.

As you mentioned in your post, you cannot use DML on the PartnerNetworkConnection in the unit test. If you are adamant about not using seeAllData, you could abstract out the ParterNetworkConnection pieces in a way that they do not get run in a unit test. While this would leave you with a suboptimal amount of code coverage, it would at least cover the remainder of your code (any business logic around SF2SF, excluding the actual connection itself).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.