Skip to main content
Respected Colleagues,

 

hope you are doing well. I am stuck with some Rest API test class problem and I don't know, what i am doing wrong. I shall be grateful to you for your kind cooperation.

 

My class : 

 

@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 = 'abcd@gmail.com',

 

                ONB2__EmailInvoiceActive__c = true

 

              );

 

                insert SubsTest;

 

                return SubsTest.Id;

 

    }

 

}

 

It is showing, insertion failed: kindly help me thereto, I shall be grateful to you for your kind consideration. Thanks and regards :)
6 个回答
0/9000