5

The solution for this is to move the queries into a Selector layer and then use dependency injection to use a mock selector during testmethods rather than the PROD selector when running normally Now I am a particular fan of the fflib pattern and ApexMocks (which exploits the StubApi) for doing all this but there are other approaches that accomplish the same ...


4

This seems probable, but I'm still very open to a better answer. It's a bug in how the vscode extension is applying the covered and uncovered code coverage lines. The styles for the covered and uncovered lines are currently defined in /src/codecoverage/decorations.ts as uncoveredLinesDecorationType and coveredLinesDecorationType. These are then applied in ...


4

I'm aware of two approaches that allow you to mock system objects like these that (depending on the system objects involved) can be used individually or together: Provide a "Plain Old Apex Object" with equivalent properties to the system object and isolate the actual access to the real system objects in a small accessor object exposing the "POAO" analogues ...


3

You have the filter convertedbusiness__c != null but when you are creating the lead, you are not setting this. Lead lead1 = new Lead(convertedbusiness__c= ??, LastName='testlead1 ', RAF_Nurture_Campaign__c = 'None', company='test', Email='testemai@email.com.invalid',Phone = '1111111111',Status ='Completed'); As no records are ...


3

That is List<Map<String,Object>>. However, you cannot do type casting directly. You can do it as below: List<object> objList = (List<object>)json.deserializeUntyped('[{"subid":"a4wgwe00000DfDRAA0","totalgs":"25","Revenue":"17"},{"subid":"a4wg0000weDfDUAA0","totalgs":"73080","Revenue":"109797"}]'); for(Object obj : objList){ Map&...


2

In the Developer Console, click on "Query Editor", then type in the query: SELECT NumLinesCovered FROM ApexCodeCoverage WHERE ApexClassOrTrigger.Name = 'myClassName' Then, check the "Tooling API" checkbox. Once you run the test, execute this query, and you'll get a result back. If you leave this tab open, you can simply click the "Rerun Query" button after ...


2

To increase coverage you simply need to ensure that each condition (either positive like an "if", or negative like an "else") in the code has a test that has data meeting the required condition. In this example you notionally need 6 tests since you have 3 different "if" statements (one for the positive, one for the negative). However, some of these variants ...


2

Your trigger is not bulkified. You have written soql query inside for loop. In case of a mass update, your trigger will soon hit governer limit and the transaction will be aborted. Make use of map to avoid such situation. Read more about them here:- Apex code best practise Now coming to your first error:- Your code coverage is 69%. You need at least 75% ...


1

Why not mock finishedTests using @TestVisble annotation public class HammerTestFollowUp implements Schedulable { public Id jobId; @TestVisible private List<AsyncApexJob> finishedTests; public void execute(SchedulableContext ctx) { List<AsyncApexJob> allTests = [SELECT Id, Status FROM AsyncApexJob WHERE Id = :this.jobId];...


1

You can deploy in Prod and choose run-specified classes and just chose your classes that cover those classes From Docs: If the code coverage of an Apex component in the deployment is less than 75%, the deployment fails. Well, this might look like a quick win, but in long run it come to haunt you. Delay the deployment until the whole org has 75%+ ...


1

Welcome to SFSE! A few things about your trigger and requirements, before getting to the testing issues: Is uwt_Tree__c.Site__c a Master-Detail field? Based on how your test is written, it seems like it probably is. If that's true, then you can do this with a rollup summary field that gets the MAX value of uwt_Tree__c.Last_Planting_Date__c, no code ...


1

Firstly, the code which you mentioned as test class is not really a test class. The syntax for test class is something like below i.e. it should have an annotation @isTest which says that, this particular code is only testing the functionality and not really changing anything in the database. You can go through salesforce trailhead moudle Apex Testing to ...


1

Your problem is you try up get a.Id before inserting a. I recommend you insert each record or collection thereof after construction. Account a = new Account(Name='Test'); Child__c child = new Child__c(Child_Name__c='Child 1',Child_Age__c=10,Household__c=a.Household_ID__c); Case c = new Case(Status='New',Household__c=a.Id); // a.Id is still null Test....


1

I was having a similar issue. I'd added "salesforcedx-vscode-core.retrieve-test-code-coverage": true into the user "settings.json" as instructed. Yet the error message about "No code coverage information" was still appearing. When I checked the Apex tests side bar there weren't any tests displayed to run. Attempting to use the green Run Tests button there ...


Only top voted, non community-wiki answers of a minimum length are eligible