0

I am having some problem while testing my rest API Class. My main class is as mentioned there

@RestResource(urlMapping='/ONB2__Subscription__c/*')
global with sharing class SubsRecord {
    @HttpGet
    global static ONB2__Subscription__c getSubsById() {
        RestRequest request = RestContext.request;
        // grab the SubscriptionId from the end of the URL
        String SubscriptionId = request.requestURI.substring(
          request.requestURI.lastIndexOf('/')+1);
        
        ONB2__Subscription__c result =  [SELECT Name, ONB2__Account__c, ONB2__AggregationPeriod__c, ONB2__AutoRenewal__c, ONB2__BankAccount__c, 
                                         ONB2__BillingPeriod__c, ONB2__CancelationDate__c, ONB2__Contact__c, ONB2__DirectDebitMandateGranted__c,
                                         ONB2__DirectDebitMandateReference__c, ON_Email__c, ONB2__EmailInvoiceActive__c
                                         
                        FROM ONB2__Subscription__c
                        WHERE Id = :SubscriptionId];
                        return result;
    }
}

My Test Class

@IsTest
        private class TestSubsRecordTest {
        static testmethod void testgetSubsById() {
        Id recordId = createTestRecord();
        // Set up a test request
        RestRequest request = new RestRequest();
        request.requestUri =
            '/services/apexrest/ONB2__Subscription__c/'
            + recordId;
        request.httpMethod = 'GET';
        RestContext.request = request;
        // Call the method to test
        ONB2__Subscription__c thisCase = SubsRecord.getSubsById();
        // Verify results
            System.assert(thisCase != null);
            System.assertEquals('Test1', thisCase.Name);
    }
    static Id createTestRecord() {
        // Create test record
                ONB2__Subscription__c SubsTest = new ONB2__Subscription__c(
                Name ='Test1',
                ONB2__AggregationPeriod__c = 'monthly',
                ONB2__AutoRenewal__c = '1d',
                ONB2__BankAccount__c = 'abcd', 
                ONB2__BillingPeriod__c = 12,
                ONB2__CancelationDate__c = (system.today()+365),
                ONB2__DirectDebitMandateGranted__c = system.today() ,
                ONB2__DirectDebitMandateReference__c= 'abdred',
                ON_Email__c = '[email protected]',
                ONB2__EmailInvoiceActive__c = true
              );
                insert SubsTest;
                return SubsTest.Id;
    }
}

The Error : System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, ONB2.SubscriptionBeforeInsert: execution of BeforeInsert

caused by: ONB2.Exceptions.ConfigurationException: Could not find counter "Subscription" please check that it actually exists in the custom settings.

Class.ONB2.Counter: line 40, column 1 Class.ONB2.CounterManager: line 16, column 1 Trigger.ONB2.SubscriptionBeforeInsert: line 8, column 1: []

I shall be grateful to you for your precious input. Thanks :)

2 Answers 2

0

This error is caused by custom code. Since this is a managed package, you will need to contact the publisher of the package to determine how to resolve this error. There may be a utility method provided for creating valid custom objects, or specific instructions on how to create the data it expects. We will not be able to provide any further guidance on the matter, unfortunately, unless a member of the publisher's support or development team happens to see this question.

0

I contacted support but did not get any reply meanwhile i made (seeallData=true) and it worked

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .