Search code examples
salesforcesandboxapex-codesoql

Creating a PaymentConnect processor connection in APEX Sandbox


Right now, I'm programming a controller for a donation system that uses Payconnect and PayPal.

For testing purposes, I want to create a sample Payment Processor Connection object using 'new pymt__Processor_Connection_c'. However, I can't upsert the connection because a required PaymentConnect setup field (pymt_PaymentConnect_Setup__c) is missing.

I've tried creating a new PaymentConnect Settings record and a new PayPal processor connection in the PaymentConnect SalesForce tab, but my SOQL query can't seem to find it. I suspect this might be because I'm programming in a Sandbox account. If this is the case, then how may I properly set up the pymt__PaymentConnect_Setup__c field in my test processor connection?

My query is:

pymt__Processor_Connection__c connection = [SELECT Id,
   pymt__Test_Mode__c, pymt__Enabled_Card_Types__c
   FROM pymt__Processor_Connection__c
   WHERE pymt__Processor_Id__c = 'PayPal'];

I'm still new to APEX and StackOverflow, so please feel tree to ask for any clarifications or for additional sections of my code.

Thanks!


Solution

  • I don't know the PaymentConnect data model terribly well, but it sounds as if in order to create your test conditions you need to create a Processor Connection that is linked to a related parent PaymentConnect Setup record. You have two options here:

    1. Recommended: Improve your understanding of the PaymentConnect data model so that you can setup all the appropriate test data prior to executing your unit tests. This requires creating both a PaymentConnect Setup record and a Connection I suspect.
    2. Less Ideal: Create all of the appropriate configuration data in your Sandbox, through the UI. In your unit tests, in order to actually see that data (and this I suspect is the SOQL problem you hit), you need to add the annotation to see production data:

      @isTest (seeAllData = true)
      

    In version 24 of the Salesforce.com API, production data is isolated from unit tests by default: Isolation of Test Data from Organization Data in Unit Tests. I'm guessing that your unit test is unable to see anything that you've created in the Sandbox because you're on v.24 of the API or higher.

    Again, though, always a more robust test where you are creating all of your configuration data and test conditions yourself.

    Hope this helps.