New answers tagged

3 votes
Accepted

First Apex Test Class | FIELD_INTEGRITY_EXCEPTION

Yeah, working with OpportunityLineItems is one of the more tedious things to test because of all the required setup. The issue(s) The immediate issue I see here is with the following line (broken onto ...
user avatar
  • 48.1k
0 votes

Test Class for Custom Controller Example

Found the answer, I needed to put the page in to test and then 'create' a new controller: PageReference pageRef = Page.Example pageRef.getParameters().put('id', String.valueOf(ExampleFields.Id)); Test....
user avatar
1 vote

Deployed code to production without code coverage

What I've discovered is that when a production ORG is in "Trial" mode, you can actually build classes directly in the ORG just like a dev environment. Once provisioned then you have to spin ...
user avatar
1 vote

Deployed code to production without code coverage

While deploying, you can choose Run Local Tests, that will run all tests in the organization and count 75% of code coverage for all code in organization and not for specific classes / triggers. https:/...
user avatar
2 votes
Accepted

Insert JournalType DUPLICATE_VALUE exception in Loyalty cloud test class

this seems like an issue of Loyalty Management. There is workaround for it, please check: https://trailblazer.salesforce.com/issues_view?id=a1p4V000002aMmsQAE&_ga=2.87831384.1731144651.1655108264-...
user avatar
5 votes

Summer 22: Deleting Public Group doesn't delete Shares in Apex Test

This looks to stem from a change made to how obsolete sharing records are handled to make this kind of cleanup of no-op (since the group is deleted, nobody is actually in it, so the share records don'...
user avatar
  • 22.2k
0 votes
Accepted

Find SearchQuery returning empty in test

You need to use Test.setFixedSearchResults, as search indexes are not updated in real-time, so it is impossible to leverage the search index correctly within a unit test. Further, even with SeeAllData=...
user avatar
  • 433k
4 votes
Accepted

When running tests during deployment, are tests ran in parallel?

No, tests run during a deployment are always run serially, never in parallel. There is no option to change that.
user avatar
  • 48.1k
1 vote
Accepted

How to select an element inside a template if true in LWC Jest test?

// Helper function to wait until the microtask queue is empty. This is needed for promise // timing when calling imperative Apex. async function flushPromises() { return Promise.resolve(); } Try ...
user avatar
  • 136
1 vote

Unlocked 2GP - Is unpackaged Setup Object data available for tests?

The good news is that the issue has been resolved. The bad news is that I don't know what changed, and I can't reproduce the issue. My best guesses at what the problem might have been are: Perhaps it'...
user avatar
  • 48.1k
1 vote
Accepted

How to write Apex unit test for a function that fetches meta data?

I'm assuming you are wanting to deploy this as a managed package, and hence why you do not know if the target organization would have any custom objects? If so, then I would make the suggestion of ...
user avatar
  • 740
1 vote
Accepted

How to get Test Coverage on a Simple Wrapper Class

You are missing testing the actual code that does work -- public static WebhookWrapper parse(String json) { return (WebhookWrapper) System.JSON.deserialize(json, WebhookWrapper.class); } You need ...
user avatar
  • 62.3k
0 votes

How to set a Date in apex test class?

Another option is using system.today().addDays(10) acc.effectiveDate__c = System.today().addDays(10);
user avatar
1 vote

I have one batch class which updates Account Name to true. But Not getting updated data in Test class inside System.assertEquals()

Your unit test found a bug. By writing more granular unit tests to evaluate each piece of functionality in your code, you might have been able to get more direct guidance to the source of the problem: ...
user avatar
  • 86.8k
0 votes
Accepted

Test Class Error for Apex Class meant to filter Quote Lines on a VF Email Template

To test a VF controller, you need to construct it as an object and then provide the parameters to the object as if they were provided by your VF Email markup So, you have ... Test.startTest(); Id ...
user avatar
  • 62.3k
1 vote

System.NullPointerException: null argument for JSONGenerator.writeStringField() test

In unit tests, you are responsible for setting up all of the data you need. As the error suggests, you can't pass a null value to writeStringField(). As your test Case is completely empty, all fields ...
user avatar
  • 48.1k
1 vote

System.NullPointerException: null argument for JSONGenerator.writeStringField() test

it is failing at this line gen.writeStringField('policyNumber', cc.Contract__r.Name); when method writeStringField receives null argument - it throws NPE. In your test, you created Case object, which ...
user avatar

Top 50 recent answers are included