New answers tagged

1 vote

Schedulable single email apex class low coverage when deployed to production

Running a Subset of Tests in a Deployment If the code coverage of an Apex component in the deployment is less than 75%, the deployment fails. If one of the specified tests fails, the deployment also ...
1 vote

How to write jest test for lightning-datatable LWC

The answer of this question can be found here: How to mock custom LWC components in JEST So you just need to mock the method from the datatable: .then(() => { const dataTableRow = ...
1 vote
Accepted

Creating attachment csv for visualforcepage in a test class

ReadFromFile() is an instance method, not a static method (because the method does not have the static keyword in its definition). To call instance methods, you need an instance of your class. So the ...
  • 52.2k
1 vote

Too many SOQL queries: 101 issue with Unit Test Methods

I know this is an old post but I was struggling with "Too many SOQL" errors in my Apex test classes for a while as well and just recently/finally got a handle on it. Here is a simplified/...
1 vote
Accepted

Test Class For Schedulable Apex Without Using (SellAllData=true)

Use Test.setCreatedDate after inserting your record(s) to set the desired created date. Note that this specifically does not work with SeeAllData=true and cannot be used on records that were not ...
  • 452k
1 vote
Accepted

No idea why trigger isn't firing

You need to query the plentyAcc again: @isTest static void testContactInfoFieldOnDelete(){ //Test Setup Integer count = 2; List<Account> accList = new List<Account>(); ...
0 votes

How do I retrieve a String from a SOQL query?

Your testmethod isn't testing any underlying code. Presumably, you would have something like this: // Given some mocked data (if any) ... Test.startTest(); // when code-under-test invoked new ...
  • 64.7k
0 votes

How do I retrieve a String from a SOQL query?

A query never returns a null result. If there are no values, the list will be empty, instead. if(!surList.isEmpty()) { String jsonString = surList[0].Full_Survey_Response__c; } else { // Do ...
  • 452k
2 votes

Apex Schedule Test Class Code Coverage

The literal and boring answer is "the same way you test any other code". Set up test data Call your method Gather results and make assertions The execute() method is still a method, and ...
  • 52.2k
1 vote

APEX Test Class Failure CPQ inserting more than 1 quote lines

I had the same issue with my test class. Solved it by adding the pricebook Id to the opportunity and quote. The line items I now create via the pricebookentry, not via the product. Hope this helps ...
0 votes

Error: Opportunity must have a primary quote in order to create an order.: [] - SBQQ CPQ Test class

An Order can be created and linked to an Opportunity. It can only be linked to a Quote when the Quote is Primary. Set ord.SBQQ__Quote__c = Null; The test should run.
  • 1
3 votes
Accepted

Salesforce Code Coverage for Batch Class - not running execute function

There can be few reason. There might be some trigger/flow that is populating those two fields on insert of account. Debug account after insert and see those field are populated or null. If not null, ...
0 votes

Salesforce Code Coverage for Batch Class - not running execute function

You have made a basic mistake error in your test class. In test classes we have to create your own data to test the code of main class. In your test class you are initialising an Account record but ...
4 votes
Accepted

How does @TestSetup work when tests run in parallel?

Note: This is opinion and experience based and may not be accurate. I believe parallel test execution is about executing multiple test classes in parallel, rather than the individual test methods in ...
  • 29.6k
-2 votes

How does Salesforce run apex tests in parallel?

The tests will be executed in parallel mode since 'Disable Parallel Apex Testing' is set to false The Apex Test Will be executed randomly Open Dev Console and then run the command So a temporary test ...

Top 50 recent answers are included