Skip to main content
4 votes
Accepted

OpportunityFieldHistory in Apex test class (field tracking - NewValue)

Testing something involving History objects certainly wouldn't be my first choice for learning about testing. 100% coverage isn't really the goal. It's nice to have, but it's not necessary. It's far ...
Derek F's user avatar
  • 63.2k
4 votes

Do mock classes need @IsTest?

Top-level classes marked @isTest do not require code coverage, and will not appear in code coverage reports. In addition, inner classes inside unit test classes do not require coverage. If you're ...
sfdcfox's user avatar
  • 500k
3 votes

Is There a Best Practice for Associating Apex Test Classes to Apex Classes?

I've heard of a standard where test classes are prefixed with "Test" or "Test_". I abhor that as they all sort together. I always use Test as a suffix of a class name. On the two ...
Ken's user avatar
  • 478
2 votes
Accepted

Is There a Best Practice for Associating Apex Test Classes to Apex Classes?

I can see this is going to get closed because it is opinion-based but let me offer the following A vendor tool, like Gearset (which is what I use), can detect via graph analysis all of the test ...
cropredy's user avatar
  • 72.5k
2 votes

Test Class for the Apex Class? In above I am calculating time spent by record in each stage? I tried writing test class but unable do test coverage?

The golden rule of unit testing is: you only gain coverage for code that is executed as part of running the test method(s) Since you currently only have a single test method, and are only working with ...
Derek F's user avatar
  • 63.2k
2 votes
Accepted

How do I get Apex Code Coverage in Visual Studio Code to show color highlighting and percentage after running a TestSuite?

Open the Command Palette (Ctrl-Shift-P/Cmd-Shift-P), and find the command SFDX: Run Apex Test Suite, and select the suite. Your code coverage will automatically be updated. You won't get code coverage ...
sfdcfox's user avatar
  • 500k
1 vote
Accepted

Financial Services Cloud: Manual rollup of AUM fails in test class, FinServ__Household__c is null

Derek F. led me down the path to figuring out what was wrong. In the test class, I needed to explicitly create the AccountContactRelation between the Household account and the Person Account, and then ...
tonydigi1's user avatar
1 vote

System.QueryException: List has no rows for assignment to SObject - In Test Class

You experience that error when you assign a SOQL query to a single record but the query doesn't find any results. One way to prevent this is to assign the results of the query to a List (in your ...
Alexander Aeons Torn's user avatar
1 vote

No Code coverage for excuted code

This is by design. Class and interface declarations don't count as executable code. Neither do System.debug calls, commented lines, test methods, and interface or abstract method declarations. You can ...
sfdcfox's user avatar
  • 500k
1 vote
Accepted

Unable to lock row or deadlock issue

Deadlocks happen in unit tests when you use shared resources, such as Custom Settings, because while unit tests are isolated from production data, they aren't isolated from each other. Sometimes it's ...
sfdcfox's user avatar
  • 500k
1 vote

Expected double-quoted property name in JSON at position 6025 (line 1 column 6026)

I think I found the error, but I think it's given from the plugin. Looking at the highlighted file in the screen above I removed all the irrelevant commas at the final element of a list.
Nicola Cantelli's user avatar
1 vote
Accepted

Schema.sObjectType.(...).isUpdateable() method is returning true but should return false

As Phil mentioned in a comment, creating a new permission set assignment and assigning it to a user doesn't actually remove the permission if it's granted elsewhere, such as from a different ...
sfdcfox's user avatar
  • 500k
1 vote

Apex Test - User email change on UserChangeEvent

I was running into a similar issue when trying to update an Experience Cloud User's Username after they verify their Email Address by clicking the link in their email. Removing Test.StartTest() and ...
Jeff Clark's user avatar
1 vote

How to write test class for chained enqueued jobs?

You can now use maximumQueueableStackDepth property of the AsyncOptions class to limit the depth of the queueable job stack, which represents the maximum number of chained jobs that can be added to ...
nica's user avatar
  • 1,430
1 vote

How can I cover the Exception in this code in Test coverage(test class)? I did everything but my knowledge is not enough please help me :(

In your unit test, create a user that doesn't have access to the record type, then use System.runAs to call that code. This should throw a DML exception.
sfdcfox's user avatar
  • 500k
1 vote

I trying to write test class for a Apex class. I covered the try statement where I couldn't cover the catch statement. Please help me to resolve

There doesn't really seem to be anything that could cause a catchable exception to be thrown. About the only thing that could throw one is pdfPage.getContent(); if your given Id is null or maybe if it'...
Derek F's user avatar
  • 63.2k
1 vote

"No test methods found in the Apex code included in the package." But coverage is at 100%?

For a 1GP package you must explicitly add unit test classes (and the Apex classes, unless they are a dependency for one or more class already in the package). You do this in the Package Manager in ...
Phil W's user avatar
  • 37.5k
1 vote

LWC deploy fails without errors

When deploying to production, 75% coverage is required. For other orgs, no code coverage is required. A deploy to production that fails to meet the code coverage requirements will fail. See Testing ...
sfdcfox's user avatar
  • 500k
1 vote

Test Code Coverage - Delete DML catch block

You can use the Test.isRunningTest method to check if the code is running in a test context and then throw a custom exception. For example, you can modify your main class code like this: @AuraEnabled ...
Tushar Jadav's user avatar
  • 2,690
1 vote
Accepted

How or do we have anyway to run ValidateMetadata via REST API before creating package version

Create a scratch org, then run the deployment against that org: sf project deploy start -o scratch-org -w 100 --dry-run -d force-app -l RunLocalTests This should give you all of the information you'...
sfdcfox's user avatar
  • 500k
1 vote

Code coverage and DMLException - How to enter Exception?

You can try set up invalid lookup key for the case in your @testSetup. For example: insert new Case(OwnerId = '005000000000000'); This will give you INVALID_CROSS_REFERENCE_KEY. You can use this ...
Mariia Illarionova's user avatar

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