0

I'm trying to put a deployment into one of our instances and am getting the above error when the Apex Class Test is running. I can't work out for the life of me why it's not working, but suspect that it may be something to do with the fact that the Apex code can't create the payment schedule on the ID listed in the test.

Here's the line of code it's erroring on:

    Integer numberPayments = 10;
    asp04__PaymentSchedule__c schedule = [SELECT Id FROM asp04__PaymentSchedule__c LIMIT 1];
    List<asp04__Payment__c> payments = new List<asp04__Payment__c>();
    Decimal amount      = 10;
    String currencyCode = 'GBP';
    Date paymentDate    = Date.newInstance(2021, 1, 31);

The same error occurs with the below code block in the same test (the test has failed twice):

 asp04__PaymentSchedule__c schedule = [SELECT Id FROM asp04__PaymentSchedule__c LIMIT 1];
 asp04__Payment__c payment = TestSuiteAsperatoFactory.CreatePayment(false, schedule.Id, 10, 'GBP', Date.newInstance(2021, 1, 31));
    payment.asp04__Payment_Stage__c = AsperatoServices.PAYMENT_STATE_COLLECTED;
    insert payment;

Can anyone help me understand why this test isn't passing?

Thanks in advance.

2
  • 3
    I don't think you've included enough code for people to help you. Are you creating/inserting an instance of asp04__PaymentSchedule__c in your test? If you're not, you should almost certainly be doing that.
    – Derek F
    Nov 20 at 15:03
  • 4
    As for the error itself: SOQL queries always return a List. Salesforce allows us to assign the result of a query to a single instance of an SObject type as syntactic sugar, but it requires that the query returns exactly one record. If your query returns 0 records, you get the error you're seeing (no rows for assignment).
    – Derek F
    Nov 20 at 15:45

0

You must log in to answer this question.

Browse other questions tagged .