You need to sign in to do that
Don't have an account?
Nihon Taisai
How can I test this for 100% coverage?
How to make Test Coverage 100%? HttpGet method
How can I test this for 100% coverage?
@HttpGet global static List<Box__c> getBox(){ RestRequest req = RestContext.request; String boxId = req.params.get('Id'); if(boxId == null) { return [SELECT Id, Title__c FROM Box__c LIMIT 1000]; } else { List<Box__c> boxList; boxList = [SELECT Id, Title__c FROM Box__c WHERE Id =: boxId LIMIT 1000]; return boxList; } }My test It works, but only 80%:
@isTest static void testBox() { Id recordId = idd(); RestRequest request = new RestRequest(); request.requestUri = System.URL.getSalesforceBaseUrl().toExternalForm() + '/services/apexrest/Box__c/' + recordId; request.httpMethod = 'GET'; RestContext.request = request; List<Box__c> b = OurClass.getBox(); for(Box__c pneBox : b){ System.assertEquals(pneBox.Id, recordId); } } static Id idd() { Box__c bb = new Box__c( Title__c = 'Title', ); insert bb; return bb.Id; }
Let us know if this will help you
All Answers
Let us know if this will help you