You need to sign in to do that
Don't have an account?
There was an unexpected error in your org which is preventing this assessment check from completing: System.QueryException: List has no rows for assignment to SObject
Hello,
Test coverage at 80% and I cant figure out why. Red highlight on Line 11 "return result;" GET request is working fine in workbench.
Account manager class:
Test coverage at 80% and I cant figure out why. Red highlight on Line 11 "return result;" GET request is working fine in workbench.
Account manager class:
@RestResource(urlMapping='/Accounts/*/contacts') global with sharing class AccountManager { @HttpGet global static Account getAccount() { RestRequest request = RestContext.request; // grab the accountId from the end of the URL String accountId = request.requestURI.substringBetween('Accounts/', '/contacts'); Account result = [SELECT ID,Name,(SELECT ID,Name FROM Contacts) FROM Account WHERE Id = :accountId ]; system.debug(result); return result; } }Test Class:
@IsTest private class AccountManagerTest { @isTest static void testGetAccount() { Id recordId = createTestRecord(); // Set up a test request RestRequest request = new RestRequest(); request.requestUri = 'https://na1.salesforce.com/services/apexrest/Accounts/'+ recordId+'/Contacts'; request.httpMethod = 'GET'; RestContext.request = request; // Call the method to test Account thisAccount = AccountManager.getAccount(); // Verify results System.assert(thisAccount != null); System.assertEquals('Test record', thisAccount.Name); } // Helper method static Id createTestRecord() { // Create test record Account accountTest = new Account( Name='Test record'); insert accountTest; Contact con1 = new Contact( AccountId = accountTest.Id, firstName = 'test', lastName = 'tester'); insert con1; return accountTest.Id; } }
@RestResource(urlMapping='/Accounts/*/Contacts')
All Answers
@RestResource(urlMapping='/Accounts/*/Contacts')
whatsappaero (https://whatsappaero.xyz/)
My blog (https://expositoryessays.org)
and if you want more shayari (https://www.topics-guru.com/search/label/Shayari?&max-results=5) then just visit our website Caption and slogan (https://www.topics-guru.com/) Homepage.